Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Example 3 — reading XML data using WebSpeed

> This example reads XML data using WebSpeed.

> The example can use the callbacks in i-sax2h.p (1 of 3), the EPI SAX Example 2 handler procedure.

> The example consists of i-saxe3s.p (1 of 2), the EPI SAX Example 3 server procedure.

> i-saxe3s.p
>     /* This particular .p is intended to be run on a server with an
>        available webserver and functioning WebSpeed broker/messenger */
>     DEF VAR hParser AS HANDLE.
>     DEF VAR hHandler AS HANDLE.
>     CREATE SAX-READER hParser.
>     /*************************************************************
>     *
>     * This is needed to support webspeed applications
>     *
>     *************************************************************/
>     {src/web/method/cgidefs.i}
>     /* run the persistent procedure that contains the callbacks */
>     RUN "i-sax2h.p" PERSISTENT SET hHandler.
>     /* give the SAX-READER the handle to the persistent procedure */
>     hParser:HANDLER =  hHandler.
>     /**************************************************************
>     *
>     * Goal: check to see if there is a xml document available on the
>     * webstream and if yes give it to the sax parser.
>     *
>     **************************************************************/
>     IF (WEB-CONTEXT:IS-XML) THEN
>        hParser:SET-INPUT-SOURCE("handle", WEB-CONTEXT).
>     hParser:SAX-PARSE( ) NO-ERROR.
>     /* By the time SAX-PARSE returns, our callbacks have been called as many
>        times as necessary and we're done processing the XML document
>        (or there was an error) */
>     IF ERROR-STATUS:ERROR THEN
>     DO:
>        IF ERROR-STATUS:NUM-MESSAGES > 0 THEN
>           /* unable to begin the parse */
>           MESSAGE ERROR-STATUS:GET-MESSAGE(1) VIEW-AS ALERT-BOX.
>        ELSE
>           /* error raised in a callback */
>           MESSAGE RETURN-VALUE VIEW-AS ALERT-BOX.
>        END.
>     ELSE
>         MESSAGE "Document parsed successfully".
>     DELETE OBJECT hParser.
>     DELETE PROCEDURE hHandler.

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