OpenEdge Development: Working with XML - Product ...
OpenEdge Development: Working with XML - Product ...
OpenEdge Development: Working with XML - Product ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Developing <strong>with</strong> <strong>XML</strong> in <strong>OpenEdge</strong><br />
Developing <strong>XML</strong>-enabled ABL applications <strong>with</strong> SAX<br />
1–8<br />
The Simple API for <strong>XML</strong> (SAX) is an application programming interface (API) for <strong>XML</strong><br />
documents. It was developed by a group of programmers, and even though it is not a W3C<br />
recommendation, it is widely used industry standard.<br />
SAX is a streaming model that processes one element at a time and provides mechanisms for<br />
you to respond to the current element before it is flushed and the parser moves on to the next<br />
element. Contrast this <strong>with</strong> the memory-resident model of DOM.<br />
When an <strong>XML</strong> document is accessed by a SAX application, as the <strong>XML</strong> parser encounters an<br />
<strong>XML</strong> element, it parses that element and provides its information to the application<br />
immediately, through a callback procedure. The callback procedure allows you to provide<br />
custom programming on how to handle each type of information that the parser provides to your<br />
program. On the other hand, if you do not have any custom code, you do not need to provide<br />
callback procedures. The parser’s default behavior is to simply read the whole document.<br />
So, while the DOM API decomposes an <strong>XML</strong> document into a set of nodes in a hierarchical<br />
tree, the SAX API decomposes the document into a series of procedure calls. Your application<br />
must act on the information presented as it is provided to the application. SAX can only stream<br />
forward during the parse. At the conclusion of the parse, nothing is left in memory.<br />
As an example, if you were parsing a list of address changes intended for your database, your<br />
application would need to validate and update each change as you retrieved it from the parse.<br />
The SAX technology built into <strong>OpenEdge</strong> also allows you to write an <strong>XML</strong> document in a<br />
forward-streaming way.<br />
SAX advantages<br />
The general advantages of SAX include:<br />
• The nature of a streaming model means that you need far less memory to process large<br />
<strong>XML</strong> documents.<br />
• You do not have to process the entire document. Use callback procedures to identify and<br />
respond to only the <strong>XML</strong> elements you are interested in.<br />
• You can halt the parse at any time.<br />
• You can parse an <strong>XML</strong> document that is not well formed.<br />
• SAX provides callback procedures that let you to provide more error handling.<br />
SAX limits<br />
The general limits of SAX include:<br />
• You cannot back up in the parse.<br />
• You must control the context. In other words, you must be able to grab the data you need<br />
as it goes by, while ignoring the data you don’t need.<br />
• There is no structure in memory to do in-place updates.