问题
I am trying to write a XML element tag that has to 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 self closing element tag, but cannot find how. Does anyone know how to do that ?
回答1:
Use writeEmptyElement()
.
But you should be aware that both forms are semantically equivalent, so any requirement that differentiates them should be viewed with suspicion.
来源:https://stackoverflow.com/questions/26980516/how-to-write-self-closing-element-tags-using-xmlstreamwriter