Server Reference Guide : ASOLib--OpenROAD Server Library : XML Parameters for Use with GSCPs : How You Can Preprocess and Postprocess the XML
 
Share this page          
How You Can Preprocess and Postprocess the XML
Method and procedure GSCPs also contain 4GL user exits intended for XML preprocessing and postprocessing.
XML Preprocessing
Preprocessing allows the XML input string to be structured around a different XML vocabulary. The input XML can then be converted or transformed by a third-party XSLT transformation engine to the correct 4GL parameter tag names and structure. Preprocessing of the XML string occurs before the XML values are assigned to 4GL parameters.
For example, the input to GSCP scp_getauthorandbooks could be transformed from an input document that uses different tag names:
<?xml version="1.0"?>
<Root>
    <author_number>101</author_number>
</Root>
XML Postprocessing
Use postprocessing to change the generated XML before it is returned to the client. For example, it may be necessary to convert or transform the generated XML tags and values into a different XML vocabulary using a third-party eXtensible Style Language Transformation (XSLT) engine. Postprocessing of the XML string occurs immediately prior to the XML being returned through the b_so_xml parameter.
For example, the GSCP scp_getauthorandbooks XML output shown in the previous example could be transformed into a document with the following format:
<Root>
    <Author ID="101">
        <Age>23</Age>
        <Name>P.S.Eudonym</Name>
    </Author>
</Root>
Example: Preprocessing
To preprocess XML data, you must create a 4GL procedure in your server application named iixmlpreprocess that has no return value. Your procedure must accept a parameter named b_so_preprocessxml of type StringObject. At runtime, any GSCP that receives input XML calls your procedure, passing the input XML into the b_so_preprocessxml parameter. Your procedure can perform the XML processing or, in turn, call other procedures based on the calling procedure (see example).
An example iixmlpreprocess procedure follows:
PROCEDURE iixmlpreprocess
(
    b_so_preprocessxml = StringObject DEFAULT NULL
)=
 DECLARE
    v_parentprocedure_name = VARCHAR(32) NOT NULL,
 ENDDECLARE
BEGIN

    v_parentprocedure_name = ProcExec(CurProcedure.Parent).ObjectSource.Name;
 
    v_parentprocedure_name = LowerCase(v_parentprocedure_name);
 
    CASE v_parentprocedure_name OF

    'scp_getauthorandbooks' :
        CALLPROC prexml_getauthorandbooks(
                                b_so_preprocessxml = BYREF(b_so_preprocessxml));
    DEFAULT:
    BEGIN
        /* Default processing is to do nothing */
    END;
 
    ENDCASE;
 END;
In the preceding code, prexml_getauthorandbooks is another user-written procedure that has specific XML processing to perform when input XML is passed to the scp_GetAuthorAndBooks GSCP.
Example: Postprocessing
To use postprocessing, you must create a 4GL procedure in your server application named iixmlpostprocess, which has no return value. Your procedure must accept a parameter named b_so_postprocessxml of type StringObject. At runtime, any call that has requested output XML data calls your procedure, passing the generated XML into the b_so_postprocessxml parameter. Your procedure can perform the XML processing or, in turn, call other procedures based on the calling procedure.
An example iixmlpostprocess procedure follows:
PROCEDURE iixmlpostprocess
(
    b_so_postprocessxml = StringObject DEFAULT NULL
)=
 DECLARE
    v_parentprocedure_name = VARCHAR(32) NOT NULL,
    i = INTEGER NOT NULL,
 ENDDECLARE
BEGIN

    v_parentprocedure_name = ProcExec(CurProcedure.Parent).ObjectSource.Name;
 
    v_parentprocedure_name = LowerCase(v_parentprocedure_name);
 
    CASE v_parentprocedure_name OF

    'scp_getauthorandbooks' :
        CALLPROC postxml_getauthorandbooks(
                               b_so_postprocessxml = BYREF(b_so_postprocessxml));
 
    DEFAULT:
    BEGIN
        /* Default processing is to remove the DTD. */

        i = b_so_postprocessxml.LocateString(
                            match         = ']>',
                            startposition = 1 );
 
        IF i < b_so_postprocessxml.Length
        THEN
            b_so_postprocessxml.LeftTruncate( endposition = i + 1);
        ENDIF;
    END;
 
    ENDCASE;
 END;