Skip to content
UPEEC

xml

Parse and build XML with xml.etree.ElementTree (plus DOM and SAX APIs).

Intermediate
Comments 0
import xml.etree.ElementTree as ET
root = ET.parse("parts.xml").getroot()
for p in root.iter("part"): print(p.get("id"), p.findtext("value"))

For untrusted XML use defusedxml to avoid entity-expansion attacks.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.