Is XML's root closing tag mandatory?

北战南征 提交于 2019-12-11 08:26:26

问题


I serialized an object in Java, and I got the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.8.0_92" class="java.beans.XMLDecoder">
  <object class="...." id="SmartLayout0">
  <!-- ... -->
  </object>

As you see, the root tag <java> is not closed.

Is it legal in XML to not close this root tag? Does the XML standard explicitly allow such shortcut?


回答1:


Yes, unlike in the non-XHTML versions of HTML, all tags in XML must be closed or be self-closing.

All elements in XML must be either self-closing or must consist of matching opening and closing tags:

element ::= EmptyElemTag | STag content ETag 


来源:https://stackoverflow.com/questions/42627382/is-xmls-root-closing-tag-mandatory

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