问题
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