OpenEdge Development: Working with XML - Product ...
OpenEdge Development: Working with XML - Product ...
OpenEdge Development: Working with XML - Product ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Reading and Writing <strong>XML</strong> <strong>with</strong> the Document Object Model (DOM)<br />
2–12<br />
i-outcus.p (2 of 2)<br />
/* Add the other fields as tags in the xml */<br />
REPEAT ix = 1 TO hBuf:NUM-FIELDS:<br />
hDBFld = hBuf:BUFFER-FIELD(ix).<br />
IF hDBFld:NAME = "CustNum" OR hDBFld:NAME = "Name" THEN NEXT.<br />
/* Create a tag <strong>with</strong> the field name */<br />
hDoc:CREATE-NODE(hField, hDBFld:NAME, "ELEMENT").<br />
/* Put the new field as next child of row */<br />
hRow:APPEND-CHILD(hField).<br />
/* Add a node to hold field value. The empty string (““) represents the<br />
value that will be set later. */<br />
hDoc:CREATE-NODE(hText, "", "TEXT").<br />
/* Attach the text to the field */<br />
hField:APPEND-CHILD(hText).<br />
hText:NODE-VALUE = STRING(hDBFld:BUFFER-VALUE).<br />
END.<br />
END.<br />
/* Write the <strong>XML</strong> node tree to an xml file */<br />
hDoc:SAVE("file","cust.xml").<br />
DELETE OBJECT hDoc.<br />
DELETE OBJECT hRoot.<br />
DELETE OBJECT hRow.<br />
DELETE OBJECT hField.<br />
DELETE OBJECT hText.<br />
A partial output of the above program appears below:<br />
<br />
<br />
<br />
USA<br />
276 North Street<br />
<br />
Boston<br />
MA<br />
02114<br />
Gloria Shepley<br />
(617) 450-0087<br />
HXM<br />
66700<br />
42568<br />
Net30<br />
35<br />
This customer is on credit hold.<br />
<br />
<br />
Finland<br />
Rattipolku 3<br />
. . .<br />
<br />
<br />
Note: The example above adds carriage returns and indentations for readability; the actual<br />
file contains one long string.