· Apr 18, 2017 1m read

TIP: Beautify XML in two lines of COS

If your handling XML then it can often be unformatted for human display.

Using a little bit of XSLT magic you can format the XML in just two lines of code...

ClassMethod Format(pXmlStream As %CharacterStream, Output pXmlStreamFormatted As %CharacterStream) As %Status
    set xslt=##class(%Dictionary.XDataDefinition).%OpenId(..%ClassName(1)_"||XSLT",-1,.sc)
    quit ##class(%XML.XSLT.Transformer).TransformStream(pXmlStream,xslt.Data,.pXmlStreamFormatted)

<xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="node()|@*">
            <xsl:apply-templates select="node()|@*"/>
Discussion (1)1
Log in or sign up to continue