Try OpenEdge Now
skip to main content
Working with XML
Reading XML Documents with the Simple API for XML (SAX) : Understanding ABL SAX : Parsing with one call or with multiple calls
 

Parsing with one call or with multiple calls

An ABL SAX application can parse an XML document using one of the following techniques:
*Single call
*Progressive scan
To use the single-call technique, the application calls the SAX-PARSE( ) method once. The parser parses the entire XML document (unless errors occur), calling all appropriate callbacks, and returns control to the line in the code following SAX-PARSE( ).
To use the progressive-scan technique, the application calls the SAX-PARSE-FIRST( ) method once to initiate parsing, then calls the SAX-PARSE-NEXT( ) method repeatedly to parse each XML token in the document. As each XML token is detected, the parser invokes the corresponding callback. After each call to SAX-PARSE-FIRST( ) or SAX-PARSE-NEXT( ), control returns to the line in the code following the SAX-PARSE-FIRST( ) or SAX-PARSE-NEXT( ).
Consider using progressive scan:
*If your business logic is complex and processes individual XML elements extensively.
To do significant processing with a single call, your callback code might have to call directly into your business logic. This might be awkward, especially when adding SAX to existing code.
To do significant processing with progressive scan, your business logic can simply call SAX-PARSE-FIRST( ) or SAX-PARSE-NEXT( ) to extract the next piece of data. The callbacks could then store incoming data, one piece at a time, for the business logic to process after the return from SAX-PARSE-FIRST( ) or SAX-PARSE-NEXT( ).
*To parse two XML sources concurrently.
After calling the SAX-PARSE( ), SAX-PARSE-FIRST( ), or SAX-PARSE-NEXT( ) methods, the application checks the value of the PARSE-STATUS attribute, as explained in Monitoring the state of the parse.