The Java EE 5 Tutorial

Comparing StAX to Other JAXP APIs

As an API in the JAXP family, StAX can be compared, among other APIs, to SAX, TrAX, and JDOM. Of the latter two, StAX is not as powerful or flexible as TrAX or JDOM, but neither does it require as much memory or processor load to be useful, and StAX can, in many cases, outperform the DOM-based APIs. The same arguments outlined above, weighing the cost/benefits of the DOM model versus the streaming model, apply here.

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:

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