background image

StAX-Enabled Clients

<< StAX Use Cases | Cursor API >>
<< StAX Use Cases | Cursor API >>

StAX-Enabled Clients

With this in mind, the closest comparisons can be made between StAX and SAX, and it is here
that StAX offers features that are beneficial in many cases; some of these include:
StAX-enabled clients are generally easier to code than SAX clients. While it can be argued
that SAX parsers are marginally easier to write, StAX parser code can be smaller and the
code necessary for the client to interact with the parser simpler.
StAX is a bidirectional API, meaning that it can both read and write XML documents. SAX
is read only, so another API is needed if you want to write XML documents.
SAX is a push API, whereas StAX is pull. The trade-offs between push and pull APIs
outlined above apply here.
Table 18­1
summarizes the comparative features of StAX, SAX, DOM, and TrAX (table
adapted from "Does StAX Belong in Your XML Toolbox?" at
http://www.developer.com/xml/article.php/3397691
by Jeff Ryan).
TABLE 18­1
XML Parser API Feature Summary
Feature
StAX
SAX
DOM
TrAX
API Type
Pull, streaming
Push, streaming
In memory tree
XSLT Rule
Ease of Use
High
Medium
High
Medium
XPath Capability
Not supported
Not supported
Supported
Supported
CPU and Memory
Efficiency
Good
Good
Varies
Varies
Forward Only
Supported
Supported
Not supported
Not supported
Read XML
Supported
Supported
Supported
Supported
Write XML
Supported
Not supported
Supported
Supported
Create, Read, Update,
Delete
Not supported
Not supported
Supported
Not supported
StAX API
The StAX API exposes methods for iterative, event-based processing of XML documents. XML
documents are treated as a filtered series of events, and infoset states can be stored in a
procedural fashion. Moreover, unlike SAX, the StAX API is bidirectional, enabling both reading
and writing of XML documents.
The StAX API is really two distinct API sets: a cursor API and an iterator API. These two API
sets explained in greater detail later in this chapter, but their main features are briefly described
below.
StAX API
The Java EE 5 Tutorial · September 2007
552