Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between XML Pull Parser and SAX Parser

I am searching for the main difference between SAX and Pull Parser . I know the SAX parser is good for handling the large XML file as it does not store the XML and traverse in only one direction. as compared to DOM. But I am unable to find the major difference between SAX and PULL. Please suggest me any link

like image 629
sharma.mahesh369 Avatar asked Oct 30 '14 11:10

sharma.mahesh369


2 Answers

The difference is the way you code your XML processor. For the SAX parser you use an event driven model where you supply a class which has methods to respond to the events which occur while the XML is being read (Oracle tutorial here).

For the pull parser you have more control over when bits of the XML get read and you can pass the parser handle around to various classes to handle different bits of the document (Oracle tutorial here).

Oracle's comparison of the technologies can be found here.

like image 107
BarrySW19 Avatar answered Sep 27 '22 22:09

BarrySW19


When Parser calls your handler, i.e. Parser pushes the event into your handler it is called Push Model of Parser, eg. SAX Parser

SAX Parser --> Handler

With push model, you do not have control over how and when the parsed iterates over the file.

When Handler class calls the parser or when handler class controls the parser when to move on the next event is called the Pull Parser. Here Handler "pulls" the XML event out of the parser. eg. StAX

Handler --> StAX Parser

for more information , please read http://tutorials.jenkov.com/java-xml/sax-vs-stax.html

like image 36
dildeepak Avatar answered Sep 27 '22 22:09

dildeepak