StAX stands for Streaming API for XML. It's a streaming Java-based, event-driven, pull-parsing API for reading and writing XML documents.
Traditionally, XML APIs are either:
- tree based (like DOM) - the entire XML content is read and assembled into an in-memory, hierarchical object graph.
- event based (like SAX) - the application registers to receive events as entities are encountered within the source document.
Both have advantages: tree based parsers allow random access to the document while the latter requires a smaller memory footprint and is usually faster. StAX sits between these two methodologies, because the application "pulls" the data from the XML data stream at its convenience. The application (not the parser) controls how to fetch data from xml. It was introduced in JSR-173 in March 2004 and it's a new feature in JDK 6.0.
StAX implementations have a reader and a writer APIs. Both with two levels: "raw" cursor access and object-based "event" access.
The "raw" cursor access classes included in JDK are:
The "event" based classes included in JDK are:
Other implementations are:
A performance comparison with a few basic sample snippets can be found here.