XML
Beginner
1 min read
Well-Formed vs Valid XML Documents
Example
<!--
WELL-FORMED: passes basic XML syntax rules
VALID: also conforms to a DTD or schema
-->
<!-- WELL-FORMED (correct) -->
<person>
<name>Alice</name>
<age>30</age>
</person>
<!-- NOT WELL-FORMED: overlapping elements -->
<!--
<person>
<name><bold>Alice</name></bold>
</person>
-->
<!-- NOT WELL-FORMED: missing closing tag -->
<!--
<person>
<name>Alice
</person>
-->
<!-- NOT WELL-FORMED: unquoted attribute -->
<!--
<person id=42>
<name>Alice</name>
</person>
-->
<!-- WELL-FORMED but NOT VALID against a schema
that only allows <name> and <age> as children -->
<person>
<name>Alice</name>
<age>30</age>
<nickname>Al</nickname>
</person>