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 />
Reading <strong>XML</strong> input into ABL<br />
2–14<br />
This section describes how to read <strong>XML</strong> input into ABL.<br />
To read in an <strong>XML</strong> file and process it:<br />
1. Create an X-document object.<br />
2. Create an X-noderef object to represent your root node.<br />
3. Use the LOAD( ) method to read the input file.<br />
4. Use the GET-DOCUMENT-ELEMENT( ) method to get the root node reference handle.<br />
5. Create an X-noderef object to represent nodes for your document.<br />
6. Using the GET-CHILD( ) method, read through the child nodes.<br />
7. Using the GET-ATTRIBUTE( ) METHOD, the NAME attribute, the NODE-VALUE attribute and<br />
other attributes and methods, access the <strong>XML</strong> data.<br />
8. Update the database or other fields as necessary.<br />
9. Delete the objects.<br />
Loading an <strong>XML</strong> file<br />
The LOAD( ) method reads the specified file into memory, parses it, optionally validates it, and<br />
makes its contents available to ABL. Once the <strong>XML</strong> file is in memory, you must get the handle<br />
to its root element by using the GET-DOCUMENT-ELEMENT( ) method. Once you have the root<br />
node handle, you can manipulate the remaining child nodes.<br />
The following code fragment demonstrates loading an <strong>XML</strong> file called myfile.xml:<br />
DEFINE VARIABLE hDocMine AS HANDLE NO-UNDO.<br />
DEFINE VARIABLE hRootMine AS HANDLE NO-UNDO.<br />
CREATE X-DOCUMENT hDocMine.<br />
CREATE X-NODEREF hRootMine.<br />
hDocMine:LOAD("FILE","myfile.xml",TRUE).<br />
hDocMine:GET-DOCUMENT-ELEMENT(hRootMine).<br />
. . .<br />
Loading an <strong>XML</strong> file from a LONGCHAR<br />
An <strong>XML</strong> file can be read from a LONGCHAR as the following code fragment demonstrates:<br />
DEFINE VARIABLE longstring AS LONGCHAR NO-UNDO.<br />
. . .<br />
hDoc:LOAD("LONGCHAR",longstring,FALSE).<br />
. . .