Mady
Mady

Reputation: 5286

Format XML generated by Xstream

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

Upvotes: 6

Views: 9249

Answers (3)

javierdotnet
javierdotnet

Reputation: 36

I've used this to :

        xstream= new XStream(new DomDriver());

But it's not so efficient than StaxDriver()

Upvotes: 1

Boris Pavlović
Boris Pavlović

Reputation: 64622

Take a look at their tutorial on tweaking the output.

Upvotes: 2

dustmachine
dustmachine

Reputation: 10814

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

Upvotes: 4

Related Questions