Search code examples
xmlstax

How to write empty element with StAX?


I'm using StAX in order to write an XML document but I can't find how to write the empty elements XML. I would like to write <element/> instead of <element></element>.


Solution

  • Use writeEmptyElement method in XMLStreamWriter class: http://download.oracle.com/javase/6/docs/api/javax/xml/stream/XMLStreamWriter.html#writeEmptyElement%28java.lang.String%29