XML parsing PULL and PUSH methodologies.

What is XML push parsing?

A push parsing model is a model where the parser pushes parsing events to the application. SAX (stands for Simple API for XML) is the most common example of a push parsing API for XML. An application using SAX would define a number of callback that would be called by the parser when certain events occur. for example, an application can define a startElement method, that the parser will call every time it sees the beginning of a new element. SAX is a one-pass parser that goes through the document once from begging to end and sends one event to the calling application for each XML construct it encounters.

What is XML pull parsing?

A pull parsing mode is a model in which the application drives the parser (in contrast to the push model, where the parser drives the application), by pulling parsed xml constructs from the parser one by one, according to its needs. StAX (Streaming API for XML) is the most prevalent Java pull parsing API. in the StAX model, an application calls the parser's next() method iteratively - each call returns the next XML construct in the document.

Historically SAX existed before StAX, and StAX was introduced to fix a few shortcomings of the SAX model - mainly that using SAX event model forces the application to maintain state variables to keep up with the document context while events are received from the parser. Wi the pull model, a more natural processing flow can be maintained, where different parts of the XML document can be delegated to different methods.

Comments

Popular posts from this blog

Log4j multiple WAR files in single EAR configuration

Java NIO2 - Watching a directory for changes. FileWatcherService.

Ubuntu Add programs to launcher (Desktop)