Friday, June 3, 2011

XML-StAX


=======================================================
What are advantages of StAX over SAX and DOM
=======================================================

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.

3) SAX is a push API, whereas StAX is pull.

=======================================================
What is StAX
=======================================================

                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).
The DOM model involves creating in-memory objects representing an entire document tree and the complete infoset state for an XML document. Once in memory, DOM trees can be navigated freely and parsed arbitrarily, and as such provide maximum flexibility for developers. However the cost of this flexibility is a potentially large memory footprint and significant processor requirements, as the entire representation of the document must be held in memory as objects for the duration of the document processing. This may not be an issue when working with small documents, but memory and processor requirements can escalate quickly with document size.

                Streaming refers to a programming model in which XML infosets are transmitted and parsed serially at application runtime, often in real time, and from dynamic sources. Moreover, stream-based parsers can start generating output immediately, and infoset elements can be discarded and garbage collected immediately after they are used. While providing a smaller memory footprint, reduced processor requirements, and higher performance in certain situations.
                Streaming models for XML processing are particularly useful
1) when your application has strict memory limitations, as with a cellphone running J2ME,
2) or when your application needs to simultaneously process several requests, as with an application server.
 


Pull Parsing Versus Push Parsing


=======================================================
What is Pull Parsing
What is 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