Pcornel
Automation · Python Automation

XML

Cheat sheet · https://pcornel.dk/topic.php?topic=5269

Back to the Topic

Answer

Python parses XML with xml.etree.ElementTree from the standard library or lxml for XPath and namespaces, as needed for NETCONF replies and other XML APIs.

Remember

  • Use ElementTree or lxml.
  • Handle namespaces explicitly.
  • lxml supports full XPath.

First checks

  • python3 -c 'import defusedxml.ElementTree as ET;ET.parse("f.xml")' — safe XML parse
  • xmllint --noout f.xml — well-formed check
  • XPath queries tested — extraction

Verify in this order

XML → safe parser → tree → XPath

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=5269

Confirmation

Confirm action

Continue?