I am using following code to format xml string. But it does not work if it has CDATA component inside, otehrwise it works fine. Any ideas?
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
EDIT : It does not format the xml below correctly :
<named-query name="aaaa">
<query>
<![CDATA[
something
]]>
</query>
</named-query>
It prints :
<named-query name="aaaa">
<query><![CDATA[
asasasasasasasa
]]></query>
</named-query>