Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

XML document as a tree

To understand structure-oriented processing it is helpful to perceive the hierarchical arrangement of elements and attributes in an XML document as a tree structure. In much simplified form, such a tree can be defined as follows:

  • Each element or attribute from the XML document corresponds to a node in the tree, which is assigned the name and the value of the element or attribute. Element names do not have to be unique here; attribute names need only be unique with respect to their element names.

  • Each element node has two ordered sequences of nodes which are directly subordinate to it, its children: a sequence of element nodes and a sequence of attribute nodes. Each of these sequences can be empty, or contain one or more nodes.

  • The first node in one of the ordered sequences is the oldest, and the last the youngest child, and consequently all the nodes which follow a node in such a sequence are referred to as younger siblings, all those in front of it as older siblings.

  • The outermost element of the XML document, which encompasses everything, is the root of the entire tree. In the same way, every other element node is at the same time also the root of a subtree. A node defines a subtree; the term subtree also applies for a single node which has no children.

  • With the exception of the root of the entire tree, each node in the tree has precisely one directly superordinate node, its parent.

  • Nodes which have no children are also called leaves.

  • Each element or attribute in the tree has a unique position, which is used to establish the connection between the description in the COBOL program and the elements or attributes currently assigned.

Example 12-32 XML document as a tree

XML document:

<a
   att="123">xxxx
   <b>yy</b>
   <b>zz
      <c>9876</c>
  </b>
  <d>rst</d>
</a>

In tree presentation:

The position and the value are noted in parentheses for each node. Element nodes are represented by solid lines, attribute nodes by broken lines.

Comments:

  • 'a' is the root of the entire tree.

  • Its children are the nodes at positions 2, 3, 4 and 6.

  • The sequence of element nodes consists of the two 'b’s' and 'd'.                             

  • The sequence of attribute nodes consists of a single node, 'att'.                               

  • 'b' at position 4 has 'd' as its younger sibling and 'b' at position 3 as its older sibling.

  • ’a’ is the parent of the two 'b's’, of 'd' and of the 'att' node

  • Node 'a' has both element and attribute nodes as children. The node at position 4 has only one element node as a child, but no attribute nodes. The nodes at positions 2, 3, 5 and 6 are leaves; they have no children, in other words neither subordinate element nor subordinate attribute nodes.