Kbase P6330: How to assign an attribute to an XML node?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Unverified
GOAL:
How to assign an attribute to an XML node?
GOAL:
How to create multiple attributes for a specific XML element?
FACT(s) (Environment):
Progress 9.1x
OpenEdge 10.x
FIX:
See the SET-ATTRIBUTE method. For example:
DEFINE VARIABLE hDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot AS HANDLE NO-UNDO.
DEFINE VARIABLE hRow AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE hText AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuf AS HANDLE NO-UNDO.
DEFINE VARIABLE hDBFld AS HANDLE NO-UNDO.
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot.
CREATE X-NODEREF hRow.
CREATE X-NODEREF hField.
CREATE X-NODEREF hText.
hDoc:CREATE-NODE (hRoot, "Customers", "ELEMENT":U).
hDoc:APPEND-CHILD (hRoot).
FOR EACH Customer WHERE Customer.CustNum < 3 NO-LOCK:
hDoc:CREATE-NODE (hRow, "Customer", "ELEMENT":U).
hRoot:APPEND-CHILD (hRow).
hRow:SET-ATTRIBUTE ("CustNum":U, STRING (Customer.CustNum)).
hRow:SET-ATTRIBUTE ("Name":U, Customer.Name).
hDoc:CREATE-NODE (hField, "Phone", "ELEMENT":U).
hRow:APPEND-CHILD (hField).
hDoc:CREATE-NODE (hText, "", "TEXT":U).
hField:APPEND-CHILD (hText).
hText:NODE-VALUE = Customer.Phone.
END.
/*
** Write the XML node tree to an XML file
*/
hDoc:SAVE ("FILE":U, "cust.xml":U).
DELETE OBJECT hDoc.
DELETE OBJECT hRoot.
DELETE OBJECT hRow.
DELETE OBJECT hField.
DELETE OBJECT hText.