Progress
External Program
Interfaces


SAX and the Progress ADE

You can use the Progress ADE to develop Progress SAX applications. This involves the following tasks:

To create a SAX Handler object, which corresponds to a procedure (.p) file to contain the SAX callbacks, follow these steps:

  1. From the Progress AppBuilder main menu, select File New. The New dialog box appears.
  2. Select the Procedures toggle box. The SAX handler template appears, as shown here:
  3. Select Sax Handler and click OK. The new Sax Handler object appears as follows:

To supply the callbacks that your SAX application requires, follow these steps:

  1. On the AppBuilder tool bar, click the Edit Code icon, as shown here:
  2. The Section combo box appears.

  3. Change the Section combo box to Procedure. The New Procedure window appears, as shown here:
  4. Select the name of the callback desired, select Override, then click OK.
  5. NOTE: ADE implements SAX callbacks as super procedures (which you can override) of the SAX Handler object.

    The Section Editor appears, as shown here:

  6. Modify the callback as desired, then save it.
  7. NOTE: If you misspell the name of a callback, at run time, it will not be invoked. Rather, the corresponding internal procedure in the super procedure will be invoked.

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.

But Progress SAX provides a solution. Three of the Progress ADE 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 information recorded in each temp-table record includes the parameters passed to startElement 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. 

Progress SAX provides context management for the following SAX callbacks:

Context Management Example

Here is a fragment that demonstrates the ADE context management system. The fragment retrieves the handle to the context management table, then finds the element added most recently:

PROCEDURE getTopElement : 
  DEFINE OUTPUT PARAMETER cElementname AS CHARACTER. 
  mhStack = DYNAMIC-FUNCTION("getStackHandle"). 
  IF VALID-HANDLE(mhStack) THEN DO: 
    DEFINE VARIABLE fld AS HANDLE. 
    DEFINE VARIABLE bh AS HANDLE. 
    bh = mhStack:DEFAULT-BUFFER-HANDLE. 
    bh:FIND-LAST() NO-ERROR. 
    fld = bh:BUFFER-FIELD("cQName") NO-ERROR. 
    cElementname = fld:BUFFER-VALUE NO-ERROR. 
  END. 
END PROCEDURE. 


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095