Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLEventWriter: how can I tell it to write empty elements?

I do not see an option within javax.xml.stream.XMLEventWriter or javax.xml.stream.XMLOutputFactory to set either up in a way so that empty elements are written (instead of explicit start and end element pairs).

I see that Woodstox has a property to do this, but it is not standardized.

Am I missing any obvious way to do this?

like image 424
Laird Nelson Avatar asked Jun 29 '10 15:06

Laird Nelson


2 Answers

writer.writeEmptyElement("some_element");
writer.writeAttribute("some_attribute", "some_value");
like image 60
user1675631 Avatar answered Oct 14 '22 06:10

user1675631


Setting property so that empty tags are generated like <x/> works with WoodStox APIs:

WstxOutputFactory factory = new WstxOutputFactory();
factory.setProperty(WstxOutputFactory.P_AUTOMATIC_EMPTY_ELEMENTS, true);

I wanted indentation in XML tags. the setIndentation method is working with neither javax.xml.stream.XMLOutputFactory nor org.codehaus.stax2.XMLOutputFactory2

like image 4
thequark Avatar answered Oct 14 '22 06:10

thequark