background image

Streaming API for XML

<< More Information about JAXB | Pull Parsing versus Push Parsing >>
<< More Information about JAXB | Pull Parsing versus Push Parsing >>

Streaming API for XML

Streaming API for XML
This chapter focuses on the Streaming API for XML (StAX), a streaming Java-based,
event-driven, pull-parsing API for reading and writing XML documents. StAX enables you to
create bidrectional XML parsers that are fast, relatively easy to program, and have a light
memory footprint.
StAX is the latest API in the JAXP family, and provides an alternative to SAX, DOM, TrAX, and
DOM for developers looking to do high-performance stream filtering, processing, and
modification, particularly with low memory and limited extensibility requirements.
To summarize, StAX provides a standard, bidirectional pull parser interface for streaming XML
processing, offering a simpler programming model than SAX and more efficient memory
management than DOM. StAX enables developers to parse and modify XML streams as events,
and to extend XML information models to allow application-specific additions. More detailed
comparisons of StAX with several alternative APIs are provided below, in
"Comparing StAX to
Other JAXP APIs" on page 551
.
Why StAX?
The StAX project was spearheaded by BEA with support from Sun Microsystems, and the JSR
173 specification passed the Java Community Process final approval ballot in March, 2004
(
http://jcp.org/en/jsr/detail?id=173
). The primary goal of the StAX API is to give
"parsing control to the programmer by exposing a simple iterator based API. This allows the
programmer to ask for the next event (pull the event) and allows state to be stored in procedural
fashion." StAX was created to address limitations in the two most prevalent parsing APIs, SAX
and DOM.
Streaming versus DOM
Generally speaking, there are two programming models for working with XML infosets:
streaming and the document object model (DOM).
18
C H A P T E R
1 8
549