XPath Data Model: Elements, Attributes, and Text Nodes

The XPath data model conceptualizes an XML document as a hierarchical tree of nodes rather than raw text. Within this tree, XML structures are mapped to specific node types, each possessing distinct properties, parent-child relationships, and value-extraction rules. This article examines how the XPath data model specifically represents the three most common node types: element nodes, attribute nodes, and text nodes.

The XPath Node Tree Structure

Before examining specific nodes, it is essential to understand that the XPath data model represents an XML document as a connected tree starting from a root node (also known as the document node). Every component of the XML document—including tags, attributes, and text content—is mapped into an abstract node object with defined properties such as node-name, parent, children, and string-value.

Element Nodes

Element nodes represent the primary structural tags within an XML document. Every XML tag pair (e.g., <item>...</item>) or self-closing tag (e.g., <item/>) becomes an element node in the XPath tree.

Attribute Nodes

Attribute nodes represent the name-value pairs defined inside an element’s opening tag (e.g., <item id="101">).

Text Nodes

Text nodes encapsulate the character data (PCDATA) found between element tags.

Node Characteristics Comparison

Node Type Has Expanded Name? Can Have Children? Considered a Child of Element? String Value Calculation
Element Yes Yes (elements, text, comments, PIs) Yes Concatenation of all descendant text nodes
Attribute Yes No No (accessed via attribute:: axis) The normalized attribute value string
Text No No Yes The character data itself