What is the difference between XML Pull Parser and SAX Parser
Asked Answered
D

2

13

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

Diarmid answered 30/10, 2014 at 11:8 Comment(2)
SAX is a pull parser, but there are others, e.g. DOM.Welbie
SAX is a push parser - StAX is a pull parser (see comparison link below)Bring
B
8

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.

Bring answered 30/10, 2014 at 11:16 Comment(0)
P
2

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

Psychiatry answered 29/8, 2016 at 6:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.