How can I strip whitepsace and newlines between xml elements using Java?
===

I have this document:

>     <tag1>
>      <tag2>
>         <![CDATA[  Some data ]]>
>      </tag2>
>     </tag1>

I want to convert it to:

>     <tag1><tag2><![CDATA[  Some data ]]></tag2></tag1>

Using java.

This does not work:

>         DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
>         dbfac.setIgnoringElementContentWhitespace(true);
>         DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
>         Document doc = docBuilder.parse(new FileInputStream("/tmp/test.xml"));
> 
>         Writer out = new StringWriter();
>         Transformer tf = TransformerFactory.newInstance().newTransformer();
>         tf.setOutputProperty(OutputKeys.INDENT, "no");
>         tf.transform(new DOMSource(doc), new StreamResult(out));
>         System.out.println(out.toString());