java xml pretty printing - preserve empty elements and white pace
- by javamonkey79
Basically, I am looking for a java library that will take this:
<foo><bar> </bar><baz>yadda</baz></foo>
And pretty print it to this:
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar> </bar>
<baz>yadda</baz>
</foo>
e.g. preserving whitespace AND blank elements
The closest I have got was with dom4j like so:
OutputFormat format = OutputFormat.createPrettyPrint();
format.setTrimText( false );
However, this does not honor the whitespace unless the element contains other character data.
I'm not opposed to writing something on my own, but I would think this has already been done, why reinvent the wheel?