XML structures

Contextual formatting often involves selecting elements that occur in specific locations within a document's structure. It is therefore necessary to first understand what XML element structures are, and to appreciate the terminology commonly used to describe relationships between parts of an XML document. Note that not all of the concepts described in this section are relevant to contextual templates but are important for later discussions on locating elements for reuse.

An element may contain a number of embedded elements. These are termed child elements. These child elements share the same parent element. In the following example, the Title element and the Para element are both children of the Chapter element, and it follows that the parent of both these two elements is the Chapter element:

<chapter>
  <title>Embedded Title</title>
  <para>Embedded paragraph.</para>
</chapter>

In addition, the Title and Para elements in the example above are sibling elements, because they share the same parent. Siblings always have a simple sequential order. The first sibling in the example is the Title element as it occurs first in the data stream. The Para element follows the Title element, and it also happens to be the last sibling. The terms preceding sibling and following sibling are used to describe ordering relationships.

The family tree analogy is taken further, as the term ancestor is used to describe any element that contains the one under discussion, no matter how many levels may separate the two. The parent element is also an ancestor element. In the following example, the Para element has three ancestors, including its parent Warning element:

<book>
  <chapter>
    <warning>
      <para>Embedded paragraph.</para>

Similarly, the term descendant is used to describe all embedded elements, including children. In the example above, the Book element has at least three descendants, including its child Chapter element.

Finally, all XML documents must contain a single element that has no parent, as in the Book element above. This is known as the root element, as it is similar to the root of a tree (the ultimate source of all the branches).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset