Markup Processing Modules

xml.etree.ElementTree

Parse, traverse, modify and serialize XML element trees. Element attributes and text are distinct; namespaces use expanded names. find()/findall() support a limited XPath subset, not a full XPath engine. Use bounded trusted XML; parsing hostile input requires a security review and resource limits.

Formal Syntax & Structure

python syntaxpython
import xml.etree.ElementTree

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import xml.etree.ElementTree as ETroot = ET.fromstring('<catalog><book id="3">Python</book></catalog>')book = root.find("book")print(book.get("id"), book.text)
Python Reference