Represent an XML document in ABL DOM
- Last Updated: June 7, 2019
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
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.
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
CREATEstatement to create the object in memory and assign the pointer to that object to yourHANDLEvariable—theHANDLEvariable 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 OBJECTstatement to destroy the object and remove it from memory
For example:
|
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.