---
source: https://iinventedlight.com/library/notes/python-xml-dom.md
title: "Python xml.dom: access an XML document as a tree of nodes"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, xml.dom: The Document Object Model API; CPython, xml.dom documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-xml-dom"
tags: [python, xml, dom, minidom, sax]
client: Librarian
sources:
  - id: S1
    title: "xml.dom: The Document Object Model API"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/xml.dom.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "xml.dom documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/xml.dom.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# Python xml.dom: access an XML document as a tree of nodes
**Answer:** The xml.dom package presents an XML document as a tree of objects, which is useful when you need random access rather than a one-pass SAX view.

## Trees versus events

A DOM implementation shows an XML document as a tree, or lets client code build that tree from scratch.

Callers then walk the structure through a set of objects with well-known interfaces.

The DOM is extremely useful for random-access applications.

SAX only lets you see one bit of the document at a time, so a text node gives you no access to its containing element.

You can assemble your own tree from SAX events, but the DOM saves you from writing that code.

## The Python mapping

The Document Object Model is defined by the W3C in stages they call levels.

The Python mapping of the API is substantially based on the DOM Level 2 recommendation.

xml.dom.minidom follows the DOM Level 1 specification.

Applications typically start by parsing some XML into a DOM.

xml.dom contains registerDOMImplementation and getDOMImplementation. EMPTY_NAMESPACE indicates that no namespace is associated with a node.

## See also

- [python-xml-minidom](https://iinventedlight.com/library/notes/python-xml-minidom/)
- [python-xml-etree](https://iinventedlight.com/library/notes/python-xml-etree/)
- [python-xml-sax](https://iinventedlight.com/library/notes/python-xml-sax/)

## Claims

- id: C1
  claim: A DOM implementation presents an XML document as a tree structure.
  source: S1
  evidence: "A DOM implementation presents an XML document as a tree structure"

- id: C2
  claim: The Python mapping is substantially based on the DOM Level 2 recommendation.
  source: S2
  evidence: "substantially based on the DOM Level 2 recommendation"

- id: C3
  claim: The model is extremely useful for random-access applications.
  source: S1
  evidence: "The DOM is extremely useful for random-access applications"

## Sources

- [S1] xml.dom: The Document Object Model API. Python Software Foundation. https://docs.python.org/3/library/xml.dom.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] xml.dom documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/xml.dom.rst . License: PSF License Version 2. Accessed 2026-11-26.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, xml.dom: The Document Object Model API; CPython, xml.dom documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
