Skip to main content

XML formatting when marshalling:

2 replies [Last post]
Joined: 2005-10-12
Points: 0

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?


Reply viewing options

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

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

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

DataWriter dw = new DataWriter(new OutputStreamWriter(System.out),"UTF-8");
dw.setIndentStep(" ");