Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Push parsing and Pull parsing of Streaming API.

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still confuse the Push parsing and Pull parsing of Streaming API. Anybody could present a simple and easy-to-understand explanation ?

Thanks
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me have a go...

As far I know the javax.xml.stream packages only deal with pull parsing and not push parsing.
The org.xml.sax packages are based on the push parsing model.

For me Pull parsing and Push Parsing represents two different ways of writing XML parsing code.

The push model requires a handler with required event handling methods (e.g in SAX startElement, endElement, characters etc. as defined in org.xml.sax.ContentHandler interface) implemented and the Handler Implementation needs to keep track of where in XML document the parser is in. In the push model the parser has control over the parsing and the parser calls the implemented handler methods. Writing a Hanlder for complex parsing is cumbersome with having to shuffle between a number of methods and keeping track of the current point in the XML document.

In the pull model you could write the whole parsing code within one method and the client application has control over the parsing. i.e. the programmer can decide when to look for the next event rather than the parser pushing events to a Handler Implemenation. Pull parsing code eliminates the disjoint coding nature of the push model. However it may be required to write a number of nested loops to accomplish parsing a XML Document. I like coding with the pull model.

Hope this helps....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic