Try OpenEdge Now
skip to main content
Working with XML
Reading XML Documents with the Simple API for XML (SAX) : ABL SAX and WebSpeed : SAX and the AppBuilder : Storing and recalling context information
 
Storing and recalling context information
The SAX specification does not say how to store and recall context information; that is, information on how XML elements are related to each other. For example, the SAX specification says that when the SAX parser encounters a new element, a startElement event should be triggered and the StartElement callback should be invoked. However, the SAX specification does not say how to determine the new element's parent.
ABL SAX provides a solution. Three of the AppBuilder templates for SAX callbacks refer to a temp-table. The temp-table and its records can be used as a stack to record context information related to that callback. When this feature is turned on:
*The AVM creates a new temp-table record each time the SAX parser encounters the beginning of a new element
*The AVM deletes the temp-table record each time the SAX parser encounters the end of the element
The information recorded in each temp-table record includes the parameters passed to the StartElement callback and the element's path (position) in the element hierarchy. For example, in the following XML example, the path of the customer element is /customer and the path of the order element is /customer/orders/order:
<customer custnum="1" name="Lift Line Skiing">
<orders>
<order ordernum="1">
</order>
</orders>
</customer>
To activate context management (which is inactive by default), call the setContextMode( ) function, as demonstrated in the following code fragment:
RUN myHandler.p PERSISTENT SET hHandler.
DYNAMIC-FUNCTION("setContextMode" IN hHandler, TRUE).
hParser:HANDLER = hHandler.
ABL SAX provides context management for the following SAX callbacks:
*StartDocument
*StartElement
*EndElement