THE PRACTICAL GUIDE · NORMANDIN SYSTEMS
Get more from XPath Syntax Cheatsheet
XPath Syntax Cheatsheet summarizes path expressions for selecting nodes and values in XML-oriented documents. XPath navigates a tree using element names, attributes, axes, and predicates. The context node and namespace bindings matter, so an expression should be tested against the actual document structure and the XPath version supported by its consumer. A cheatsheet works best as a memory aid while you practice a concrete task. Read the command or syntax together with its arguments, placeholders, and surrounding context. Similar-looking options can have very different meanings, and an example written for one platform or version may need adjustment elsewhere. Keep the reference beside a small test case, use read-only examples first when possible, and check the relevant help output before applying an unfamiliar command to valuable files or a running service.
Guide updated October 13, 2026
How to use this tool
- Identify the operation you want to perform and find the matching section of the reference. Read the whole example before copying any part of it.
- Identify the document context and namespaces, choose a path expression, and compare selected nodes with a small sample tree.
- Review the example below and compare its expected behavior with a small sample of your own input before continuing.
- Try the adapted example on a small test case, compare the result with the explanation, and save the command with a note about the context in which it works.
SEE IT IN PRACTICE
A worked example
//book[@id='b1']
book elements whose id attribute equals b1
The descendant search finds matching book elements, while the predicate filters them by the specified attribute value.
Context and namespaces explain many empty results
An XPath expression is evaluated relative to a context node, and element names can belong to namespaces even when the document's visible tags look simple. A default namespace in XML can require an explicit prefix binding in the query environment. If a path returns no nodes, inspect those assumptions before replacing it with a broad wildcard. Test a small sample and compare the exact selected nodes, including attributes and text nodes when the expression targets them.
Predicates and axes change selection meaning
A positional predicate can apply at a particular step rather than to an entire final result set, and different axes navigate different relationships. Read the expression step by step and check the intermediate selection if the consumer provides that visibility. Functions and syntax also depend on the XPath version. A reference can illustrate the concept, but the actual parser determines available features. Keep a representative XML fixture with the expression so changes in document nesting or namespace use are caught during review.
When this tool is useful
- Locate a specific XML element
- Review attribute-filter syntax
- Understand context and namespaces in document selection
Tips for a better result
- Check namespaces, context, predicate order, and result cardinality before using an expression in an automation or data pipeline.
- Replace example paths, identifiers, and names deliberately. Copying a reference command unchanged can target a different file, branch, service, or environment from the one you intended.
- Keep the source and the settings used for this result together. That makes a later comparison or correction easier, especially when another person needs to reproduce the same outcome.
Frequently asked questions
Why does an XPath miss visibly present XML elements?
Default XML namespaces can make an unprefixed name match nothing even when the document visibly contains that tag. XPath version differences also affect available functions.
Does this page execute the examples?
The cheatsheet is a reference. You read its examples and use them in your own editor, terminal, or application. Understand the effect and adapt placeholders before running commands in an environment that contains important data.
What if an example behaves differently on my system?
Check your installed version, platform, shell, and configuration. Read the command help or language documentation for that environment. References summarize common behavior, while available options and defaults can vary between implementations.
What happens to the information I enter?
The utility processes your input in this browser. Some tools retain field values in browser storage or the URL; avoid entering secrets in shareable fields. Page and asset requests still go to the hosting provider. Read the privacy and offline-use notes for details.