/* e-outcus.p - Export the Customer table to an xml file*/
DEFINE VARIABLE hDoc AS HANDLE.
DEFINE VARIABLE hRoot AS HANDLE.
DEFINE VARIABLE hRow AS HANDLE.
DEFINE VARIABLE hField AS HANDLE.
DEFINE VARIABLE hText AS HANDLE.
DEFINE VARIABLE hBuf AS HANDLE.
DEFINE VARIABLE hDBFld AS HANDLE.
DEFINE VARIABLE i AS INTEGER.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hRow.
CREATE X-NODEREF hField.
CREATE X-NODEREF hText.
hBuf = BUFFER code_mstr:HANDLE.
/*set up a root node*/
hDoc:CREATE-NODE(hRoot,"CODEMSTR","ELEMENT").
hDoc:APPEND-CHILD(hRoot).
FOR EACH CODE_mstr WHERE CODE_fldname MATCHES "pt_part_type":
hDoc:CREATE-NODE(hRow,"CODEMSTR","ELEMENT"). /*create a row node*/
hRoot:APPEND-CHILD(hRow). /*put the row in the tree*/
hRow:SET-ATTRIBUTE("CODE_FLDNAME",STRING(CODE_fldname)).
/*hRow:SET-ATTRIBUTE("Code_Value",CODE_value).*/
/*Add the other fields as tags in the xml*/
REPEAT i = 1 TO hBuf:NUM-FIELDS:
hDBFld = hBuf:BUFFER-FIELD(i).
IF hDBFld:NAME = "code_fldname" THEN NEXT.
/*create a tag with the field name*/
hDoc:CREATE-NODE(hField, hDBFld:NAME, "ELEMENT").
/*put the new field as next child of row*/
hRow:APPEND-CHILD(hField).
/*add a node to hold field value*/
hDoc:CREATE-NODE(hText, "", "TEXT").
/*attach the text to the field*/
hField:APPEND-CHILD(hText).
hText:NODE-VALUE = STRING(hDBFld:BUFFER-VALUE).
END.
END.
/*write the XML node tree to an xml file*/
hDoc:SAVE("file","d:\code.xml").
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hRow.
DELETE OBJECT hField.
DELETE OBJECT hText.