I want to format the output XML generated by Xstream, to make it more readable. Currently, a newline is added after each element but I would like newline to be added after every attribute. Is there a way to do this?
Pretty Print Writer is used by default to format the output of the xml but this doesn't suffice for me. I want newline to be added after every
To access XML formatting options, choose Tools > Options > Text Editor > XML, and then choose Formatting.
XStream's primary purpose is for serialization. It allows existing Java objects to be converted to clean XML and then restored again, without modifications. This is particularly useful as a form of persistence (no complicated database mappings required) or for sending objects over the wire.
For most use cases, the XStream instance is thread-safe, once configured (there are caveats when using annotations) Clear messages are provided during exception handling to help diagnose issues. Starting with version 1.4.
XStream includes a PrettyPrintWriter
After building your XStream...
XStream xstream = //...whatever
Instead of:
// p is my object needing xml serialization
xstream.toXML(p)
Use something like this to make it pretty:
BufferedOutputStream stdout = new BufferedOutputStream(System.out);
xstream.marshal(p, new PrettyPrintWriter(new OutputStreamWriter(stdout)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With