project BLF > class XML > method ConvertXmlToTableDetail


Parameters


ihComponentinputhandle
ihStartNodeinputhandle
ihCurrentTableinputhandle
irParentRowidinputrowid
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method XML.ConvertXmlToTable
method XML.ConvertXmlToTableDetail


program code (program1/xml.p)

assign oiReturnStatus = -98.

if ihStartNode:local-name = ""
then vcNodeName = ihStartNode:name.
else vcNodeName = ihStartNode:local-name.

create x-noderef vhNode in widget-pool "non-persistent".

Assign vlDone = false.

/*if vcNodeName begins "table-":U
then do:                        */
find first tKnownTable where
           tKnownTable.tcTableName = Substring(vcNodeName,2,-1,'CHARACTER':U) no-error.
If Available tKnownTable
Then Do:

    assign vhCurrentTable = (if available tKnownTable
                             then tKnownTable.thTableHandle
                             else ?).
    /* Get out of here if you cannot find the desired table in the context 
       it is not necessary to read further on */
    if not valid-handle(vhCurrentTable) 
    then DO :
        ASSIGN oireturnstatus = 0.
        return.
    END.

    /* Create a reference between parent and child table */
    vhCurrentTable:buffer-create().
           
    if irParentRowid <> ?
    then do :
        create tTableRef.
        assign tTableRef.trParentRowid = irParentRowid
               tTableRef.trChildRowid = vhCurrentTable:rowid.
    
        assign vhColumn              = vhCurrentTable:buffer-field ("tc_ParentRowid":U)
               vhColumn:buffer-value = string (irParentRowid).
    end.
    
    vhColumn = ?.
    vhColumn = vhCurrentTable:buffer-field ("tc_Rowid":U) no-error.
    if vhColumn <> ?
    then vhColumn:buffer-value = string (vhCurrentTable:rowid).

    do viCnt = 1 to ihStartNode:num-children :
        ihStartNode:get-child(vhNode,viCnt).       
        <M-6 run ConvertXmlToTableDetail (input  ihComponent (ihComponent), 
                                  input  vhNode (ihStartNode), 
                                  input  vhCurrentTable (ihCurrentTable), 
                                  input  vhCurrentTable:rowid (irParentRowid), 
                                  output viFcReturnSuper (oiReturnStatus)) in XML>
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            return.
        end.
    end.

    Assign vlDone = True.
end.

    /* if it is not a table, then try to read fields, or just fall further down in the structure */
IF Not vlDone 
Then Do:
    if valid-handle(ihCurrentTable)
    then assign vhColumn = ihCurrentTable:buffer-field(vcNodeName) no-error.
        
    if valid-handle (vhColumn)
    then do :        
        
        /* Read value from text node behind, and put it in buffer-value of vhColumn */
        <M-3 run SetFieldValue (input  ihStartNode (ihNode), 
                                input  vhColumn (ihField), 
                                output viFcReturnSuper (oiReturnStatus)) in XML>
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            return.        
        end.
    
        Assign vlDone = True.
    end.
End.

IF Not vlDone 
Then do viCnt = 1 to ihStartNode:num-children :
    ihStartNode:get-child(vhNode,viCnt).
    
    <M-7 run ConvertXmlToTableDetail (input  ihComponent (ihComponent), 
                                  input  vhNode (ihStartNode), 
                                  input  ? (ihCurrentTable), 
                                  input  irParentRowid (irParentRowid), 
                                  output viFcReturnSuper (oiReturnStatus)) in XML>
    if viFcReturnSuper <> 0
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        return.
    end.
end.

delete object vhNode.

assign oiReturnStatus = 0.