Push Parsers - Events are generated by the API in the form of callback functions like startDocument(), endDocument() and are beyond control of programmer. We as a programmer could handle the events but generation of events is beyond control.
Pull Parsers - Events are generated when we call some API. Example shown below.
So we as programmer can decide when to generate events.
int eventType = xmlr.getEventType();
while(xmlr.hasNext()){
eventType = xmlr.next();
//Get all "Book" elements as XMLEvent object
if(eventType == XMLStreamConstants.START_ELEMENT &&
xmlr.getLocalName().equals("Book")){
//get immutable XMLEvent
StartElement event = getXMLEvent(xmlr).asStartElement();
System.out.println("EVENT: " + event.toString());
}
}
, The client only gets (pulls) XML data when it explicitly asks for it.
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.