There are a lot of ways to pretty print XML, but I have yet to find one using a ColdFusion function.
This is a common question, but again I want to do this within ColdFusion.
There are a lot of ways to pretty print XML, but I have yet to find one using a ColdFusion function.
This is a common question, but again I want to do this within ColdFusion.
see top answer of: http://stackoverflow.com/questions/376373/pretty-printing-xml-with-javascript. Try it with XmlTransform()
. If it doesn't work, pick a Java XSLT engine like http://saxon.sourceforge.net/ as suggested
A quick search on http://cflib.org turned up xmlIndent().
<pre>#xmlIndent(xmlString)#</pre>
I use a Java solution XOM for this purpose, so you'd need to have its jar in your classpath for it work. Following answer in original Java code:
<cfset xmlString = [your xml here]/>
<cfscript>
encoding = "ISO-8859-1";
parser = createObject("java", "nu.xom.Builder").init();
doc = parser.build(xmlString);
out = createObject("java", "java.io.ByteArrayOutputStream").init();
Serializer serializer = new Serializer(out, encoding);
// bunch of options
serializer.setIndent(4);
serializer.setMaxLength(64);
serializer.setPreserveBaseURI(true);
serializer.write(doc);
serializer.flush();
</cfscript>
<cfoutput>#out.toString(encoding)#</cfoutput>