问题
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
回答1:
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)));
回答2:
Take a look at their tutorial on tweaking the output.
回答3:
I've used this to :
xstream= new XStream(new DomDriver());
But it's not so efficient than StaxDriver()
来源:https://stackoverflow.com/questions/8943000/format-xml-generated-by-xstream