Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Schemas and validity

Valid

A well-formed document that also conforms to a declared grammar — a DTD, an XSD schema or a RELAX NG grammar.

Validity is always relative to a grammar. "Is this valid XML?" has no answer on its own; the question is whether the document is valid against a particular schema, and the same document can be valid against one and invalid against another.

Nothing validates by default. A DOCTYPE or an xsi:schemaLocation is a pointer, not an instruction, and most parsers ignore both unless asked. If validity matters to your pipeline, you have to run the check deliberately.

Defined in
XML 1.0 §2.8
Category
Schemas and validity
Also written
validity, schema-valid

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • A document that violates the DTD it declares is still read without complaint.

    document.xml
    <!DOCTYPE note [<!ELEMENT note (to)><!ELEMENT to (#PCDATA)>]>
    <note><from>who</from></note>

    What the engine returns

    Well-formed.
  • Validation is where content is finally judged: this is not an integer.

    schema.xsd
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="v" type="xs:integer"/>
    </xs:schema>
    value
    banana

    What the engine returns

    Invalid as xs:integer.

What catches people out

  • "Valid" is used loosely to mean "parses". If someone says a document is valid, ask against what.
  • A schema reference in a document is a hint. Supplying the schema yourself is the only way to be sure which one was used.
  • Validity is not a security control. A valid document can still carry an entity attack in its prolog.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.