1

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?

Xenos
  • 3,351
  • 2
  • 27
  • 50
  • 1
    It's not legal. If you're using XMLEncoder, I suspect you forgot to call XMLEncoder.close(), which I assume will generate the closing tag. – Joe Mar 06 '17 at 13:57
  • @Joe You got it right, a missing `close()` was the issue, but since the parser was OK with such XML, I wasn't sure whether closing tag is fully mandatory. – Xenos Mar 06 '17 at 14:20

1 Answers1

2

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 
kjhughes
  • 106,133
  • 27
  • 181
  • 240