Automation · Data Formats › XML
XPath
Cheat sheet · https://pcornel.dk/topic.php?topic=5833
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.
Remember
- XPath selects nodes with path expressions.
- Predicates in [] filter nodes.
- Namespaced elements need prefixes.
First checks
xmllint --xpath '//*[local-name()="interface"]/*[local-name()="name"]' file.xml— namespace-agnostic XPathpython3 -c 'from lxml import etree'— lxml XPath- Namespace map for queries — correctness
Verify in this order
XML tree + XPath → selected nodes
Where it usually breaks
Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5833