project BLF > class XML > method ReadXmlSub

Description

Submethod of ReadXML. This recursive method reads all nodes (or starts reading from a certain node and child nodes, if the starting node name is given). It fills the tNodes temp-table with type 'N'.


Parameters


ihParentinputhandle
iiNodeParentIdinputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method XML.ReadXML
method XML.ReadXmlSub


program code (program1/xml.p)

CREATE X-NODEREF vhNode in widget-pool "non-persistent".


do viCount = 1 to ihParent:num-children:
    ihParent:get-child(vhNode,viCount).    

    /*set the value if the node is a text-node*/
    IF vhNode:name = "#text":U And
       vlStartReading     
    THEN DO:
                
        IF Trim(vhnode:node-value) <> "" 
        THEN DO:            
            FIND CURRENT tnodes.
            ASSIGN tNodes.tcNodeValue = vhnode:node-value.
        END.                
    END.
    
    /*check the node for further info*/
    ELSE DO:
    
        /*if the nodename is the same as the tag or the tag is empty then start filling tNodes*/
        IF Trim(vhNode:LOCAL-NAME) = vcTag Or
           vcTag = ''
        THEN DO:            
            vlStartReading = TRUE.
        END.  
    
        IF vhNode:LOCAL-NAME <> "" 
        THEN DO:    
        
            IF vlStartReading 
            THEN DO:    
                CREATE tNodes.
                ASSIGN 
                    tNodes.tiNodeId = vicounter
                    tNodes.tcNodeName = vhNode:LOCAL-NAME
                    tNodes.tiNodeParentId = iiNodeParentId
                    tNodes.tcNodeType = 'N':U
                    viCounter = viCounter + 1
                    viCurrentId = tNodes.tiNodeId.
            End. /*IF vlStartReading */
            
            <M-1 run ReadXmlSub
               (input  vhNode (ihParent), 
                input  viCurrentId (iiNodeParentId), 
                output viFcReturnSuper (oiReturnStatus)) in XML>  
            If viFcReturnSuper <> 0
            Then Assign oiReturnStatus = viFcReturnSuper.
            If viFcReturnSuper < 0
            Then Do:
                Delete Object vhNode.
                Return.
            End.    

            IF vlStartReading 
            THEN Do: 
                <M-2 run ReadXMLAttrib
                   (input  vhNode (ihNode), 
                    input  viCurrentId (iiNodeParentId), 
                    output viFcReturnSuper (oiReturnStatus)) in XML>
                If viFcReturnSuper <> 0
                Then Assign oiReturnStatus = viFcReturnSuper.
                If viFcReturnSuper < 0
                Then Do:
                    Delete Object vhNode.
                    Return.
                End.
            End. /*IF vlStartReading */
                       
        END. /*IF vhNode:LOCAL-NAME <> "" */
        
        /*stop filling tNodes if the node name equals the tag and if the tag is not empty*/
        IF Trim(vhNode:LOCAL-NAME) = vcTag And
           vcTag <> ''
        THEN DO:
            vlStartReading = FALSE.
        END.
        
    END.    
end.

Delete Object vhnode.