background image

Pull Parsing Versus Push Parsing

<< Streaming Versus DOM | Comparing StAX to Other JAXP APIs >>
<< Streaming Versus DOM | Comparing StAX to Other JAXP APIs >>
P
ULL
P
ARSING
V
ERSUS
P
USH
P
ARSING
79
Pull Parsing Versus Push Parsing
Streaming pull parsing refers to a programming model in which a client applica-
tion calls methods on an XML parsing library when it needs to interact with an
XML infoset--that is, the client only gets (pulls) XML data when it explicitly
asks for it.
Streaming push parsing refers to a programming model in which an XML parser
sends (pushes) XML data to the client as the parser encounters elements in an
XML infoset--that is, the parser sends the data whether or not the client is ready
to use it at that time.
Pull parsing provides several advantages over push parsing when working with
XML streams:
· With pull parsing, the client controls the application thread, and can call
methods on the parser when needed. By contrast, with push processing, the
parser controls the application thread, and the client can only accept invo-
cations from the parser.
· Pull parsing libraries can be much smaller and the client code to interact
with those libraries much simpler than with push libraries, even for more
complex documents.
· Pull clients can read multiple documents at one time with a single thread.
· A StAX pull parser can filter XML documents such that elements unnec-
essary to the client can be ignored, and it can support XML views of non-
XML data.
StAX Use Cases
The StAX specification defines a number of uses cases for the API:
· Data binding
· Unmarshalling an XML document
· Marshalling an XML document
· Parallel document processing
· Wireless communication
· SOAP message processing
· Parsing simple predictable structures
· Parsing graph representations with forward references