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 bananaWhat the engine returns
Invalid asxs: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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- ToolsXSD validatorRuns the check against a schema you supply.
- Schema errorsThis element is not expectedThe most common way validation fails once you do run it.
- Schema errorsMissing child element(s)The other one: right elements, incomplete document.
Related terms
- Well-formedA document that obeys XML's syntax rules: one root element, strictly nested tags, quoted attribute values, escaped markup characters.
- XML Schema (XSD)The W3C schema language: a grammar written in XML itself, with datatypes, namespaces and a type system.
- DTDThe original XML schema language: element and attribute declarations written in their own non-XML syntax, plus the entity declarations nothing else provides.
- RELAX NGA schema language built around patterns rather than types, expressing repetition, alternation and interleaving far more directly than XSD.
- Content modelThe rule saying what an element may contain: which children, in what order, how many times, and whether text is allowed.
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.