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

StAX

A streaming API where your code pulls the next event from the parser, rather than the parser pushing events at your code.

StAX keeps SAX's flat memory profile and gives control back to the caller. Your loop asks for the next event, which means you can stop early, hand the cursor to another function, or switch strategies partway through a document — none of which is natural in a callback model.

It is the usual choice in the JVM world, and the same pull-parser shape appears elsewhere under other names. Between it and SAX the trade is stylistic more than practical: both stream, neither can look backwards.

Defined in
JSR 173
Category
Parsing and processing
Also written
Streaming API for XML, pull parsing

Why there is no demo

Nothing here to execute

Like SAX, StAX is an API shape rather than anything a document records. A demonstration here would be a claim about a library rather than about XML, and this site only publishes claims it can execute.

What catches people out

  • Stopping early is StAX's real advantage: you can abandon a document after the element you wanted, which SAX cannot do cleanly.
  • Cursor and event-iterator APIs coexist. The cursor is faster; the iterator is easier to pass around.
  • As with SAX, there is no backtracking. Keep what you will need.

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.