Skip to main content

XML formatting when marshalling:

2 replies [Last post]
grunge
Offline
Joined: 2005-10-12

This is not a critical issue, but when marshalling to XML using the following output setting:

m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

Objects with only @XmlAttribute's declared, output like the following:

I would like the output to be as follows:

Is there any way I can influence the marshalling XML output logic to achieve this?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
heinrich_soebke
Offline
Joined: 2005-03-15
kohsuke
Offline
Joined: 2003-06-09

Good point. When I rewrote the marshaller for better performance, I sort of ended up removing this "empty element" feature assuming that it hurts performance.

I'll see if it can be easily resurrected without compromising the performance. If you want to track the progress you are welcome to file an issue on http://jaxb.dev.java.net/

One way that works today is to use com.sun.xml.bind.marshaller.DataWriter class.

[code]
DataWriter dw = new DataWriter(new OutputStreamWriter(System.out),"UTF-8");
dw.setIndentStep(" ");
marshaller.marshal(object,dw);
[/code]