Parse an XML document
- Last Updated: June 7, 2019
- 1 minute read
- OpenEdge
- Version 13.0
- Documentation
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( )orSAX-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 fromSAX-PARSE-FIRST( )orSAX-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 Monitor the state of the parse.