You are reading O'Reilly XForms Essentials by Micah Dubinko. (What is this?) - Buy XForms Essentials Online

Going Deep: The XPath Data Model

In the XPath view of things, elements, attributes, text, comments, processing instructions, and even namespaces are represented internally as nodes connected in a tree shape. Some nodes, such as elements, may have child nodes, while others, such as attributes, have no children, as restricted by XML rules. A special node, called the root node, serves as the ultimate ancestor node.

Example 3.2, “A basic XML document, represented as text ” shows a short XML document, and Figure 3.1, “A basic XML document, represented as nodes in the XPath data model” shows how that document would be represented by a tree of nodes.

In this example, note that neither the XML declaration nor the DOCTYPE declaration produce any nodes. Thus, these XML data structures are effectively invisible to XPath and, by extension, XForms. On the other hand, notice how each element node has two namespace nodes attached: one for the xmlns:html declaration on the root element, which applies throughout, and one for the built-in declaration of the xml prefix, as seen in the attribute xml:lang. Even a short document like this generates a huge number of nodes!

Each node has a set of properties that are exposed to XPath in various ways.

Additionally, some nodes have the following properties:

A collection of nodes without duplicates is referred to as a node-set.