Pretty Print XML Data In JSP
How do I pretty print (ie. with indentation) XML data in the JSP? I have the following code:
Solution 1:
XSLT has a simple means of doing this via the xsl:output element. If you can apply an XSLT, I suggest using a stylesheet like this (based on the identity transformation):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Solution 2:
If you want a simple solution, don't bother with xsl while setting response for JSP to look at, just do stuff.replaceAll("<", "& lt;").replaceAll(">","& gt; "); You don't need anything else; no XSL transformation needed here. Use technologies when they are essential, unless I am missing something here.
Solution 3:
You can pretty print JSLT with Pretty Diff at http://prettydiff.com/?m=beautify It will do exactly what you need. Consider the following example:
<a>
<c:out value="<strong>some content</strong>"/>
</a>
Pretty Diff is capable of recognizing multidimensional tags so long as the nested tag is in quotes.
Post a Comment for "Pretty Print XML Data In JSP"