Well-formed vs. Valid

Contact Us or call 1-877-932-8228
Well-formed vs. Valid

Well-formed vs. Valid

It's possible for an XML document to be well formed, but not valid:

  • A well-formed XML document is one that follows the syntax rules described earlier and repeated below.
  • A valid XML document is one that conforms to a specified structure.

For an XML document to be validated, it must be checked against a schema, which is a document that defines the structure for a class of XML documents. XML documents that are not intended to conform to a schema can be well-formed, but they cannot be valid.

XML Syntax Rules (revisited)

  1. There must be one and only one document element.
  2. Every open tag must be closed.
  3. If an element is empty, it still must be closed.
    • Poorly-formed: <tag>
    • Well-formed: <tag></tag>
    • Also well-formed: <tag />
  4. Elements must be properly nested.
    • Poorly-formed: <a><b></a></b>
    • Well-formed: <a><b></b></a>
  5. Tag and attribute names are case sensitive.
  6. Attribute values must be enclosed in single or double quotes.