Try OpenEdge Now
skip to main content
Working with XML
Reading and Writing XML with the Document Object Model (DOM) : The ABL DOM interface : Representing an XML document in ABL DOM
 

Representing an XML document in ABL DOM

DOM builds a hierarchical tree structure that persists in memory and represents your entire XML document. With the ABL interface, you can call the parser to build such a tree for you in memory from an XML document. The DOM tree is then available for you to easily manipulate using standard tree-traversal logic. For example, an XML document may represent a list of address changes generated from a self-service Web site. Your application might need to traverse the tree and do some logical validation before using the XML data in the tree to update customer address records in your database.
You could also use the API to programmatically build a DOM tree in memory and then write that tree out as an XML document. For example, you may need to generate a list of customer address changes for a business partner.
Note: ABL has defined a set of extensions to ABL to allow the use of XML through the DOM interface. These extensions provide ABL applications with the basic input, output, and low-level data manipulation capabilities required to use data contained in XML documents. They are not intended to provide access to the entire DOM interface, nor are they intended to include all the high-level constructs.
In an ABL application, an X-document object can represent an XML document. Like all ABL objects, the programming flow for using an X-document object follows this pattern:
*Define a variable of type HANDLE
*Use the appropriate CREATE statement to create the object in memory and assign the pointer to that object to your HANDLE variable—the HANDLE variable is your interface to the object
*Use attributes and methods on the handle to initialize or configure the object
*Use attributes and methods on the handle to complete your programming tasks
*Use the DELETE OBJECT statement to destroy the object and remove it from memory
For example:
DEFINE VARIABLE hDocument AS HANDLE NO-UNDO.
CREATE X-DOCUMENT hDocument.
. . .
DELETE OBJECT hDocument.
Since an X-document represents the tree of an XML document, it is a container for the branches and leaves of that tree. In XML, the branches and leafs are elements. In DOM, the branches and leafs are called nodes. There is a relationship between elements and nodes, but it is not a direct one-for-one correspondence. In DOM, a single XML element may be further decomposed into many nodes. The relationships between DOM nodes in a tree and the relationship of XML components can follow slightly different logic. For example, an attribute of an XML element is thought of as a part of the element. In DOM, that attribute becomes a separate node related to the node that represents its associated element.
So, how do you keep all this straight? Basically, when you begin a programming task, you need to ensure that your XML input documents are valid, well-formed XML and that the design of your output XML documents produces valid, well-formed XML. For the rest of your project, you will be immersed in ABL and DOM logic. Think in terms of DOM nodes and the rules of DOM relationships, and you will be successful.