Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Parsing · XML

Direct answer

Parse XML with a proper library — [xml] or Select-Xml in PowerShell, lxml or ElementTree in Python — taking care of namespaces, which NETCONF replies always use.

When to use this

Use this when parsing XML in PowerShell or Python, including namespaces such as in NETCONF replies.

First 30 seconds

1. Use safe XML parsers (defusedxml, lxml with resolve_entities=False).

2. Disable DTD/external entities.

3. Handle encoding.

4. Stream large files (iterparse).

5. Validate after parsing.

Operational verification

XML → safe parser → tree

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 parsing XML in PowerShell or Python, including namespaces such as in NETCONF replies.
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.

2 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 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as encoding/BOM issues, delimiter/quoting ambiguity, duplicate keys, namespace drift, scalar coercion, invalid schema assumptions and parser success without consumer-valid semantics, choosing the cases most relevant to decoding/lexing/structural parse, schema validation, error location and preventing parser success from being treated as business-semantic validity.

Step 2 Common mistakes Narrow the fault
  • Parsing untrusted XML with unsafe parsers.
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
  • Use [xml], Select-Xml, lxml or ElementTree.
  • Register namespaces before querying.
  • Avoid regex for XML.
Key checks
  • python3 -c 'import defusedxml.ElementTree as ET;ET.parse("f.xml")' — safe parse
  • xmllint --noout --nonet file.xml — no network entity loading
  • XXE protections enabled — security
ReferenceWhy it matters1 section · depth on demand

In depth

Parsing XML reads the document into a tree that code can navigate and query. Choose the parser for the job: ElementTree (standard library) for most cases, lxml for XPath and speed, streaming parsers (iterparse) for very large files.

from defusedxml.ElementTree import fromstring        # safe for untrusted input
root = fromstring(response_text)
[xml]$x = Get-Content export.xml
$x.SelectNodes('//vlan') | ForEach-Object { $_.id, $_.name }

Common problems: namespaces not passed to queries (finds nothing), encoding declarations that do not match the bytes, and XML External Entity (XXE) attacks when untrusted XML is parsed with entity resolution enabled.

ReferenceImportant terms & boundaries1 section · depth on demand
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 > Parsing. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.w3.org/TR/xml/ · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For decoding/lexing/structural parse, schema validation, error location and preventing parser success from being treated as business-semantic validity, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?