Nov 10

You need to open an InputStream for the URL and pass that to your DocumentBuilder

DocumentBuilderFactory factory = 
   DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(url.openStream()); 

written by objects \\ tags: , , ,

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); 

written by objects \\ tags: , ,