XPath 1.0 has nodetypes, where the nodes are the information derived from the document. There are seven type of nodes and are all described below. The nodes have a string value which is either a part of node or a string value computed from its descendant nodes.


The Attribute node represents the attribute of the element. An attribute is not a child of the element but it occurs before the children of the element. Element is said to be the parent of attribute node (this is different from DOM). Attribute nodes are never shared by elements.


Every comment is a Comment node, except for comment in side DTD’s. String value of comment is text inside <!-- and --> (excluding these tags).


The Element nodes are represents of elements and are present in the order of the occurrence, in the document. The string value of the element node is the combination of all the text node descendants of the element node in the order they occur in the document. It can have element node, comment node, PI node and text node as children


Namespace nodes represents namespace associated with element. Element is parent of the namespace nodes, however namespace is not child of the element. The string value of namespace node is absolute namespace URI that is in namespace prefix or expanded name in relative URI.

Processing Instruction

The PI node exists for every processing instruction except for that occurs in DTD. An XML declaration is not processing instruction and there is no node corresponding to that. String value of PI node is part of instruction following target and any whitespace. It does not include ?>.


The Root node is the first node of a document. It does not have any parent node. The element nodes, comments, PI’s, comment nodes can occur as children for root element. String value of a root node is the text node descendant of root node.


Character data is also called Text nodes. A text node does not have another text node as immediate sibling. String value of text node is character data. CDATA is also treated as text node with the tags <!CDATA[ and ]> removed. Characters inside comments, PI’s and attributes do not belong to text node.

Example of XML node types

<?xml version="1.0" encoding="UTF-8"?>




            <dept id="accounts">











In example above:

  • root – Root node
  • student, school, employee … - Element node
  • raju, lucy – text node
  • id – Attribute node


›› go to examples ››