XPath Reference
Reference for XPath 1.0/2.0/3.0 expressions for navigating and querying XML documents.
Path Expressions
XPath uses path expressions to select nodes from an XML document, similar to file paths. The / separator selects children, // selects descendants at any depth. Predicates in [brackets] filter nodes by index or condition. The @ prefix selects attributes. Wildcards * match any element, node() matches any node. Expressions can be absolute (starting from /) or relative.
- /
- Child axis
- //
- Descendant axis
- @
- Attribute selection
/book/title //title anywhere @lang Functions and Operators
XPath provides built-in functions: text(), contains(), starts-with(), name(), count(), position(). XPath 2.0+ adds sequence types, for-expressions, and richer type system. Operators include =, !=, <, >, and logical and/or. String, number, and boolean functions support common operations. XPath 3.0 adds dynamic evaluation and function items. Most parsers support XPath 1.0; 2.0+ requires Saxon or similar.
- text()
- Text content of node
- contains()
- Substring test
- position()
- Index in context
title/text() contains(@class, "active") li[position()=1]