|
Oct
13
|
Use an XSL transformation with the xsl:strip-space instruction.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(
new StreamSource("strip-space.xsl"));
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);



April 28th, 2010 at 11:33 pm
Thanks a lot, saved my day
April 28th, 2010 at 11:47 pm
No worries
March 15th, 2011 at 8:12 am
great tip
, works well with the Transformer trick for indenting
June 29th, 2011 at 8:10 pm
Hi,
Thanks for the info. Saved a lot of my time.
This works like a charm when used in conjuction with the “Reformat/Auto-format” functionality of Visual Studio.
November 28th, 2011 at 8:12 pm
Thanks lot
November 28th, 2011 at 8:19 pm
no worries