Skip to Content
Java and XML, 3rd Edition
book

Java and XML, 3rd Edition

by Brett McLaughlin, Justin Edelson
December 2006
Intermediate to advanced content levelIntermediate to advanced
479 pages
13h 52m
English
O'Reilly Media, Inc.
Content preview from Java and XML, 3rd Edition

Chapter 8. Pull Parsing With StAX

The two APIs we’ve examined thus far—SAX and DOM—take two different approaches to XML document parsing. A SAX parser notifies your code, through predefined interfaces, of various events as the parser traverses the XML document. DOM creates a tree structure in memory that is then returned to your code as one whole piece.

This chapter looks at an additional API—StAX—that uses yet a third approach for XML parsing commonly referred to as pull parsing. Pull parsing is similar to SAX in that your code interacts with the document as it is being read by the parser. The difference lies in how this interaction occurs. As the name implies, when you use a pull parser, your code asks the parser for the next event. Your code need not implement any special interfaces, as is necessary with SAX. As a result, code that uses a pull parser may be more concise and easier to read than the corresponding SAX code.

In addition, StAX provides a set of classes for writing XML documents, something SAX doesn’t handle at all. Unlike DOM or any other tree-based parser, the document does not remain in memory while it is being built.

We will also look at an alternative pull parser API—XmlPull—which was the predecessor to StAX but continues to be useful in memory-constrained applications, specifically those that use J2ME.

StAX Basics

StAX is an acronym for Streaming API for XML. It is Java Specification Recommendation (JSR) 173, sponsored by BEA with the goal of standardizing the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java & XML Data Binding

Java & XML Data Binding

Brett McLaughlin
Mastering Java 11 - Second Edition

Mastering Java 11 - Second Edition

Dr. Edward Lavieri Jr., Mandar Jog
XML in a Nutshell, 3rd Edition

XML in a Nutshell, 3rd Edition

Elliotte Rusty Harold, W. Scott Means

Publisher Resources

ISBN: 059610149XSupplemental ContentErrata Page