Nodes

XPath allows the following nodes to be selected.

  • Root Node

  • Element Nodes

  • Attribute Nodes

  • Text Nodes [text()]

  • Comment Nodes [comment()]

  • Namespace Nodes

    Should Namespaces be treated as nodes?

    Note

    Deprecated since XPath 2.0
  • Processing Instruction Nodes [processing-instruction()]

  • ... any Node [node()]

  • Use the comment() function to match any comment.

    //comment()

    Returns all comments in the document.

  • Use the text() function to match any text nodes.

    /bookstore/book/author/text()

    Returns the text nodes for the all author elements.

  • Use the processing-instruction() function to match PIs.

    //processing-instruction()
    //processing-instruction('xml-stylesheet')

    The first XPath returns all the PIs in the document and the second returns all 'xml-stylesheet' PIs.

XPath assumes Entities, DocTypes and CData sections to be normalized before the expression is evaluated.