Nodes

A node conforms to one of the types of nodes that are defined for XPath. These node types include: document, element, attribute, text, processing instruction, comment, and namespace nodes.

The nodes of a sequence form one or more trees that consist of a document node and all of the nodes that are reachable directly or indirectly from the document node. Every node belongs to exactly one tree, and every tree has exactly one document node. A tree whose root node is a document node is referred to as a document. A tree whose root node is not a document node is referred to as a fragment.

The following XML document includes a document element, named product, which contains a description element. The product element has an attribute named pid (purchase order ID). The description element contains elements named name, details, price, and weight.

<product xmlns="http://posample.org" pid="100-101-01">  
  <description>                                               
    <name>Snow Shovel, Deluxe 24"</name>                       
    <details>A Deluxe Snow Shovel, 24 inches wide, ergonomic
            curved handle with D-Grip</details>                                       
    <price>19.99</price>                                       
    <weight>2 kg</weight>                                    
  </description>                                           
</product>

Node identity

Each node has a unique identity. This means that two nodes are distinguishable even though their names and values might be the same. In contrast, atomic values do not have an identity. Every instance of an atomic value (for example, the integer 7) is identical to every other instance of that value.

Document order

Among all of the nodes in a hierarchy, there is a total ordering called document order, in which each node appears before its children. Document order corresponds to the order in which the nodes appear when the node hierarchy is represented in XML format:
  • The document node is the first node.
  • Element nodes occur before their children.
  • Namespace nodes immediately follow the element node with which they are associated.
  • Attribute nodes occur after namespace nodes, or their associated element node, if no namespace nodes exist.

    Attribute nodes and namespace nodes are not children of an element node, but the associated element node is their parent node.

    The relative order of attribute nodes is arbitrary, but this order does not change during the processing of an XPath expression.

  • Element nodes, text nodes, processing instruction nodes, and comment nodes can be children of an element node or a document node.
  • The relative order of siblings is determined by their order in the node hierarchy.
  • Children and descendants of a node occur before siblings that follow the node.

Node properties

Each node has properties that describe characteristics of that node. For example, a node's properties might include the name of the node, its children, its parent, its attributes, and other information that describes the node. The node kind determines which properties are present for specific nodes.

A node can have one or more of the following properties:
node name
The name of the node (expressed as a QName).
parent
The node that is the parent of the current node.
type name
The dynamic (run-time) type of the node.
children
The sequence of nodes that are children of the current node.
attributes
The set of attribute nodes that belong to the current node.
string value
A string value that can be extracted from the node.
typed value
A sequence of zero or more atomic values that can be extracted from the node.
target
Identifies the application to which a processing instruction is directed. The target is an NCName (local name with no colons).
content
The content of a processing instruction, text node, or comment node.