跳到主要内容
uencoder

XPath Reference

Reference 为 XPath 1.0/2.0/3.0 expressions 为 navigating 和 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
/book/title
//
Descendant axis
//title anywhere
@
Attribute selection
@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
title/text()
contains()
Substring test
contains(@class, "active")
position()
Index in context
li[position()=1]

相关工具

参考链接