How to write self-closing element tags using XMLStreamWriter

老子叫甜甜 提交于 2019-12-13 16:58:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!