XPath
XPath query language for XML — the LINQ of the XML world
#XPath
XPath is a query language for selecting nodes in XML documents. The XML world has used XPath to query document trees since 1999.
For .NET developers: XPath resembles LINQ for XML. Both let a developer query a tree of data with a compact, declarative syntax.
XPath is not a standalone tool. XSLT uses XPath for matching and selecting nodes. XQuery uses XPath as its navigation syntax. XPath is also available directly in .NET through XPathNavigator and through PhoenixmlDb.
#What's Here
-
Path Expressions — The core of XPath: navigating the document tree with
/,//, predicates, and axes. This is where most of your day-to-day work happens. -
Functions — Comprehensive reference for XPath 4.0's 240+ built-in functions, organized by category: string, numeric, date/time, sequence, map, array, math, higher-order, and more.
-
Operators and Comparisons — Arithmetic, comparison, logical operators, and the difference between value and general comparisons.
-
Data Types — How XPath's type system works, type casting, and interaction with schema types.
#XPath by Example
Given this XML:
<catalog>
<book isbn="978-0-123456-78-9" category="programming">
<title>Effective C#</title>
<author>Bill Wagner</author>
<price currency="USD">39.99</price>
<published>2017-03-15</published>
</book>
<book isbn="978-0-987654-32-1" category="data">
<title>XML in a Nutshell</title>
<author>Elliotte Harold</author>
<price currency="USD">49.99</price>
<published>2004-09-01</published>
</book>
</catalog>
|
Task |
XPath |
LINQ Equivalent |
|---|---|---|
|
All books |
|
|
|
Book titles |
|
|
|
Books over $40 |
|
|
|
First book |
|
|
|
Book by ISBN |
|
|
|
All prices anywhere |
|
|
|
Programming books |
|
|
XPath expressions are more concise than the equivalent LINQ code. XPath also works with any XML tool, not only .NET.