Parsing and processing
Parser
The component that reads XML text and reports its structure to an application, or reports a fatal error and stops.
The specification calls it a processor and gives it one hard obligation: on a well-formedness error it must report the error and must not continue passing normal parsed data to the application. That is why XML tooling fails loudly where HTML tooling guesses.
Which parser you run changes the wording you see, not the verdict. This site runs libxml2, which is also what PHP's DOM and SimpleXML, Python's lxml and Ruby's Nokogiri use underneath — so the message on an error page here is usually the message you already saw in your own stack.
- Defined in
- XML 1.0 §1
- Category
- Parsing and processing
- Also written
- XML processor
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.
The parser stops at the first fatal error and reports it, rather than recovering.
document.xml <a><b></a> <c>this is never reached</c>What the engine returns
Opening and ending tag mismatch: b line 1 and a (line 1)And when a document is well-formed it says nothing at all.
document.xml <a><b/></a>What the engine returns
Well-formed.
What catches people out
- Permissive parsers exist and will accept documents libxml2 rejects. That makes them useful for recovery and dangerous for interchange.
- The line number in an error message is where the parser gave up, which is often not where the mistake is.
- A parser is not a validator. Well-formedness is all you get unless a schema is supplied.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- ToolsXML validatorThe parser's verdict and its verbatim message.
- Parse errorsPremature end of data in tagThe clearest case of a message pointing somewhere other than the mistake.
Related terms
- Well-formedA document that obeys XML's syntax rules: one root element, strictly nested tags, quoted attribute values, escaped markup characters.
- DOMAn API that parses a whole document into a navigable tree in memory, where every node can be reached from any other.
- SAXA streaming API that pushes events at your code — start element, characters, end element — as it reads, without building a tree.
- SerializationTurning a document tree back into text — choosing quoting, escaping, empty-element spelling, indentation and encoding.
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.