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.

Parsing and processing

SAX

A streaming API that pushes events at your code — start element, characters, end element — as it reads, without building a tree.

SAX inverts control: you register handlers, the parser calls them, and memory use stays flat no matter how large the document is. It is how you process a document bigger than your machine, and it is the only sensible approach for a multi-gigabyte export.

You pay for that in state. There is no parent to walk up to and no way to look ahead, so any context you need — which element you are inside, what you have seen already — you have to track yourself.

Defined in
SAX 2.0 (de facto)
Category
Parsing and processing
Also written
Simple API for XML, push parsing

Why there is no demo

Nothing here to execute

SAX is a shape of API, not a property of a document. Nothing in a file distinguishes one that was parsed with SAX from one parsed into a tree, so there is no claim here that could be executed. What can be shown is on the DOM page: the cross-tree expression there is exactly what SAX cannot answer without you keeping the state yourself.

What catches people out

  • Character data can arrive in several callbacks for one run of text. Accumulate rather than assuming one call per text node.
  • There is no going back. If you need an earlier element, you had to have kept it.
  • SAX has no standard for XML namespaces beyond what the implementation gives you; check whether yours reports prefixes or expanded names.

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.