How to write self-closing element tags using XMLStreamWriter

I am trying to write an XML element tag that should look like this:

<case type="" player=""/>

My code is:

doc.writeStartElement("case");
doc.writeAttribute("type", type);
doc.writeAttribute("player", "");
doc.writeEndElement();

But, as I expected, a closing tag is added at the end, so it looks like this:

<case type="" player=""></case>

I am trying to write a tag for the closing element but cannot find. Does anyone know how to do this?

+2
source share
1 answer

Use writeEmptyElement() .

But you should know that both forms are semantically equivalent , so any requirement that distinguishes them should be considered with suspicion.

+4
source

All Articles