1) StAX-enabled clients are generally easier to code than SAX clients. StAX parser code can be smaller and the code necessary for the client to interact with the parser simpler.
2) 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.
The StAX project was initiated by BEA . The goal of the StAX API is to give "parsing control to the programmer by exposing a simple iterator based API. StAX was created to address limitations in the SAX and DOM.
Streaming Versus DOM
Generally speaking, there are two programming models for working with XML infosets: document streaming and the document object model (DOM).
Pull Parsing Versus Push Parsing
Streaming pull parsing refers to a programming model in which a client application 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 invocations 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 unnecessary to the client can be ignored, and it can support XML views of non-XML data.
No comments:
Post a Comment