OpenEdge Development: Working with XML - Product ...
OpenEdge Development: Working with XML - Product ...
OpenEdge Development: Working with XML - Product ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Reading and Writing <strong>XML</strong> <strong>with</strong> the Document Object Model (DOM)<br />
2–8<br />
Since an X-document represents the tree of an <strong>XML</strong> document, it is a container for the branches<br />
and leaves of that tree. In <strong>XML</strong>, the branches and leafs are elements. In DOM, the branches and<br />
leafs are called nodes. There is a relationship between elements and nodes, but it is not a direct<br />
one-for-one correspondence. In DOM, a single <strong>XML</strong> element may be further decomposed into<br />
many nodes. The relationships between DOM nodes in a tree and the relationship of <strong>XML</strong><br />
components can follow slightly different logic. For example, an attribute of an <strong>XML</strong> element is<br />
thought of as a part of the element. In DOM, that attribute becomes a separate node related to<br />
the node that represents its associated element.<br />
So, how do you keep all this straight? Basically, when you begin a programming task, you need<br />
to ensure that your <strong>XML</strong> input documents are valid, well-formed <strong>XML</strong> and that the design of<br />
your output <strong>XML</strong> documents produces valid, well-formed <strong>XML</strong>. For the rest of your project,<br />
you will be immersed in ABL and DOM logic. Think in terms of DOM nodes and the rules of<br />
DOM relationships, and you will be successful.<br />
Representing a DOM node in ABL<br />
In essence, X-document represents the collection of nodes, their content of the nodes, and all<br />
the relationships between nodes.<br />
The X-noderef object is an ABL object that is a reference to any node in a DOM tree (except a<br />
DOCUMENT node, which is the X-document). In ABL, you can create a handle to an X-noderef<br />
object, which in turn is a cursor pointing to a DOM node in a DOM tree (represented by an ABL<br />
X-document object).<br />
The life cycle of an X-noderef object is similar to the X-document object’s. For example:<br />
DEFINE VARIABLE hNode AS HANDLE NO-UNDO<br />
.<br />
CREATE X-NODEREF hNode.<br />
. . .<br />
DELETE OBJECT hNode.<br />
There are many types of DOM nodes as identified by the SUBTYPE attribute of both the<br />
X-document and X-noderef objects. Some types of nodes may have child nodes of various<br />
types, and others are leaf nodes that cannot have anything below them in the document structure.<br />
The ABL X-noderef object can be one of the following DOM node types, as indicated by the<br />
SUBTYPE attribute:<br />
• ATTRIBUTE<br />
• CDATA-SECTION<br />
• COMMENT<br />
• DOCUMENT-FRAGMENT<br />
• ELEMENT<br />
• ENTITY-REFERENCE<br />
• PROCESSING-INSTRUCTION<br />
• TEXT<br />
The default subtype is ELEMENT.