Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

XPath

Direct answer

XPath selects nodes in an XML document with path expressions, such as //interface[name='Gi1']/enabled. It is used in NETCONF filters, Select-Xml and lxml queries.

When to use this

Use this when selecting XML nodes with XPath expressions, predicates and namespaces.

First 30 seconds

1. XPath selects nodes in XML.

2. Handle namespaces (prefix maps or local-name()).

3. Test queries on samples.

4. NETCONF filters use XPath or subtree filters.

5. Keep expressions readable.

Operational verification

XML tree + XPath → selected nodes

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
XML parsing and document structure
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformXML parsing and document structure · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when selecting XML nodes with XPath expressions, predicates and namespaces.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Common mistakes Narrow the fault
  • XPath without namespace prefixes returning nothing.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • XPath selects nodes with path expressions.
  • Predicates in [] filter nodes.
  • Namespaced elements need prefixes.
Key checks
  • xmllint --xpath '//*[local-name()="interface"]/*[local-name()="name"]' file.xml — namespace-agnostic XPath
  • python3 -c 'from lxml import etree' — lxml XPath
  • Namespace map for queries — correctness
ReferenceWhy it matters1 section · depth on demand

What it is

XPath selects nodes in XML documents and is used in NETCONF filters.

ReferenceImportant terms & boundaries3 sections · depth on demand

In depth

XPath is a query language for selecting parts of an XML document: elements by path, by attribute values, by position or by content. It is used in NETCONF filters, XSLT, and XML libraries in Python and PowerShell.

ExpressionSelects
/interfaces/interfaceAll interface elements under the root
//interface[name='Gi1']Interface with that name anywhere
//vlan/@idAll vlan id attributes
//interface[enabled='true']/nameNames of enabled interfaces
count(//interface)Number of interfaces
from lxml import etree
tree = etree.parse("config.xml")
ns = {"if": "urn:ietf:params:xml:ns:yang:ietf-interfaces"}
print(tree.xpath("//if:interface[if:enabled='false']/if:name/text()", namespaces=ns))

Example

root.xpath('//if:interface[if:name="Gi1"]/if:enabled', namespaces={'if': 'urn:ietf:params:xml:ns:yang:ietf-interfaces'})
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docXML parsing and document structure current

Authoritative/upstream documentation reviewed for bounded claims in XML > XPath. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.w3.org/TR/xml/ · confidence 94%
Confirmation

Confirm action

Continue?