javaxmlsaxparserstax

What is 'Push Approach' and 'Pull Approach' to parsing?


Under the push parsing approach, a push parser generates synchronous events as a document is parsed, and these events can be processed by an application using a callback handler model

This is the text given in the book Pro XML Development with Java about SAX 2.0.

As for StAX, the book says:

Under the pull approach, events are pulled from an XML document under the control of the application using the parser.

I want to ask, what is the meaning of the highlighted text ? An answer befitting a beginner is appreciated :)


Solution

  • Basically, a push is when the parser says to some handler, "I have a foo, do something with it." A pull is when the handler says to the parser, "give me the next foo."

    Push:

    if (myChar == '(')
        handler.handleOpenParen(); // push the open paren to the handler
    

    Pull:

    Token token = parser.next(); // pull the next token from the parser