lxml has been mentioned. You might also check out lxml.objectify for some really simple manipulation.

>>> from lxml import objectify
>>> tree = objectify.fromstring(your_xml)
>>> tree.weather.attrib["module_id"]
'0'
>>> tree.weather.forecast_information.city.attrib["data"]
'Mountain View, CA'
>>> tree.weather.forecast_information.postal_code.attrib["data"]
'94043'
Answer from Ryan Ginstrom on Stack Overflow
🌐
Python
docs.python.org › 3 › library › xml.etree.elementtree.html
xml.etree.ElementTree — The ElementTree XML API
January 29, 2026 - XML is an inherently hierarchical data format, and the most natural way to represent it is with a tree. ET has two classes for this purpose - ElementTree represents the whole XML document as a tree, and Element represents a single node in this tree.
🌐
GeeksforGeeks
geeksforgeeks.org › python › xml-parsing-python
XML parsing in Python - GeeksforGeeks
June 28, 2022 - Our goal is to process this RSS feed (or XML file) and save it in some other format for future use. Python Module used: This article will focus on using inbuilt xml module in python for parsing XML and the main focus will be on the ElementTree XML API of this module.
Discussions

A Roadmap to XML Parsers in Python – Real Python
Heh, this would have been so useful for me a week ago, when I needed to parse an XML. Found xmltodict and it served its purpose beautifully - for what I needed at least. More on reddit.com
🌐 r/Python
14
88
October 19, 2021
Best python libraries to manage XML files

https://lxml.de/

More on reddit.com
🌐 r/Python
8
17
January 25, 2017
Top answer
1 of 9
19

lxml has been mentioned. You might also check out lxml.objectify for some really simple manipulation.

>>> from lxml import objectify
>>> tree = objectify.fromstring(your_xml)
>>> tree.weather.attrib["module_id"]
'0'
>>> tree.weather.forecast_information.city.attrib["data"]
'Mountain View, CA'
>>> tree.weather.forecast_information.postal_code.attrib["data"]
'94043'
2 of 9
10

You want a thin veneer? That's easy to cook up. Try the following trivial wrapper around ElementTree as a start:

# geetree.py
import xml.etree.ElementTree as ET

class GeeElem(object):
    """Wrapper around an ElementTree element. a['foo'] gets the
       attribute foo, a.foo gets the first subelement foo."""
    def __init__(self, elem):
        self.etElem = elem

    def __getitem__(self, name):
        res = self._getattr(name)
        if res is None:
            raise AttributeError, "No attribute named '%s'" % name
        return res

    def __getattr__(self, name):
        res = self._getelem(name)
        if res is None:
            raise IndexError, "No element named '%s'" % name
        return res

    def _getelem(self, name):
        res = self.etElem.find(name)
        if res is None:
            return None
        return GeeElem(res)

    def _getattr(self, name):
        return self.etElem.get(name)

class GeeTree(object):
    "Wrapper around an ElementTree."
    def __init__(self, fname):
        self.doc = ET.parse(fname)

    def __getattr__(self, name):
        if self.doc.getroot().tag != name:
            raise IndexError, "No element named '%s'" % name
        return GeeElem(self.doc.getroot())

    def getroot(self):
        return self.doc.getroot()

You invoke it so:

>>> import geetree
>>> t = geetree.GeeTree('foo.xml')
>>> t.xml_api_reply.weather.forecast_information.city['data']
'Mountain View, CA'
>>> t.xml_api_reply.weather.current_conditions.temp_f['data']
'68'
🌐
Python
docs.python.org › 3 › library › xml.html
XML Processing Modules — Python 3.14.3 documentation
Source code: Lib/xml/ Python’s interfaces for processing XML are grouped in the xml package. It is important to note that modules in the xml package require that there be at least one SAX-compliant...
🌐
DataCamp
datacamp.com › tutorial › python-xml-elementtree
Python XML Tutorial: Element Tree Parse & Read | DataCamp
December 10, 2024 - Learn how you can parse, explore, modify and populate XML files with the Python ElementTree package, for loops and XPath expressions. ... Get your team access to the full DataCamp for business platform. Run and edit the code from this tutorial onlineRun code · As a data scientist, you'll find that understanding XML is powerful for both web-scraping and general practice in parsing a structured document.
🌐
Reddit
reddit.com › r/python › a roadmap to xml parsers in python – real python
r/Python on Reddit: A Roadmap to XML Parsers in Python – Real Python
October 19, 2021 - I just refuse to use anything with xml. Json or yaml only. ... always use lxml, whether going for etree-style, sax-style, or pull parsing. (using another frontend on top of lxml is still valid) don't use lxml.objectify. Instead, pass a custom lookup to the parser (trivial if using LXML's builtin xml/html parsing support; easy enough if you use bs4 as your frontend (just pass parser.makeelement).
Find elsewhere
🌐
Real Python
realpython.com › python-xml-parser
A Roadmap to XML Parsers in Python – Real Python
September 25, 2023 - In this tutorial, you'll learn what XML parsers are available in Python and how to pick the right parsing model for your specific use case. You'll explore Python's built-in parsers as well as major third-party libraries.
🌐
Tutorialspoint
tutorialspoint.com › home › python › python xml processing
Python XML Processing
February 21, 2009 - The xml package has an ElementTree module. This is a simple and lightweight XML processor API. XML is a tree-like hierarchical data format. The 'ElementTree' in this module treats the whole XML document as a tree.
🌐
Python
docs.python.org › 3 › library › xml.dom.minidom.html
xml.dom.minidom — Minimal DOM implementation
The xml.dom.minidom module is essentially a DOM 1.0-compatible DOM with some DOM 2 features (primarily namespace features). Usage of the DOM interface in Python is straight-forward.
🌐
Rdegges
rdegges.com › 2013 › quickly-extract-xml-data-with-python
Randall Degges - Quickly Extract XML Data with Python
LXML is pretty great because it allows you do some advanced things with XML, but on the downside: it requires C libraries (yuck!) that are annoying to install locally, and adds another dependency to your project. Instead of going the LXML route, I’d like to suggest using Python’s built in xml.etree module.
🌐
Python
wiki.python.org › moin › PythonXml
PythonXml
pyexpat - a fast, low-level XML parser with an event-based callback interface · Sax - the xml.sax package, a Python implementation of the well-known low-level SAX API
🌐
GeeksforGeeks
geeksforgeeks.org › python › reading-and-writing-xml-files-in-python
Reading and Writing XML Files in Python - GeeksforGeeks
January 12, 2026 - XML (Extensible Markup Language) is a standard format for storing and exchanging data. It is both human-readable and machine-readable. Let’s look at two libraries used for XML parsing in Python.
🌐
Bright Data
brightdata.com › blog › how-tos › parsing-xml-in-python
How to Parse XML in Python? Multiple Methods Covered
September 16, 2025 - It’s a built-in module in Python’s standard library, which means you don’t need to install anything explicitly. For example, you can use the findall() method to find all the url elements from the root and print the text value of the loc element, like this: import xml.etree.ElementTree as ET import requests url = 'https://brightdata.com/post-sitemap.xml' response = requests.get(url) if response.status_code == 200: root = ET.fromstring(response.content) for url_element in root.findall('.//{http://www.sitemaps.org/schemas/sitemap/0.9}url'): loc_element = url_element.find('{http://www.sitemaps.org/schemas/sitemap/0.9}loc') if loc_element is not None: print(loc_element.text) else: print("Failed to retrieve XML file from the URL.")
🌐
LearnPython.com
learnpython.com › blog › read-xml-into-python
How to Read XML Files into Python | LearnPython.com
XML files consist of hierarchical structures organized into elements and contents. These elements encapsulate the data and provide a way to represent relationships between different pieces of information. This is not unlike Python dictionaries, which store elements as key-value pairs.
🌐
Alteryx Community
community.alteryx.com › t5 › Alteryx-Designer-Desktop-Discussions › Reading-locally-stored-XML-files-in-Python-Jupyter-with-Alteryx › td-p › 745321
Solved: Reading locally stored XML files in Python (Jupyte... - Alteryx Community
April 11, 2021 - I was wondering if there was any way in which I can directly read the XML file stored locally, in my Jupyter notebook within Alteryx and replicate my script. Any suggestions would be greatly appreciated and do let me know in case any further details are required, thank you! Solved! Go to Solution. ... Solved! Go to Solution. ... The input on the Python tool is optional, so you can use it as the first tool in a stream of tools.
🌐
PyPI
pypi.org › project › xml-python
xml-python
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
freeCodeCamp
forum.freecodecamp.org › python
Navigating and extracting XML in Python - Python - The freeCodeCamp Forum
February 5, 2023 - Hi, I’m trying to find a way to extract certain elements from the note data in this xml document: F 1 4 3 1 half I now need the data from the tied element, and whilst extracting the data from pitch, I had no problem, as I simply itterated through pitch as follows: for pitch in myroot.ite...
🌐
Martiandefense
book.martiandefense.llc › notes › coding-programming › python › xml-basics-with-python
XML Basics with Python | Martian Defense NoteBook
This query will return the titles of all books in the books.xml document where the price is greater than 30. Python provides a number of modules for parsing XML, including the built-in xml.etree.ElementTree module (commonly shortened to ElementTree or ET), and the third-party lxml and xmltodict ...
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › scenarios › xml
XML parsing — The Hitchhiker's Guide to Python
from xmlschema import XMLSchema, etree_tostring # load a XSD schema file schema = XMLSchema("your_schema.xsd") # validate against the schema schema.validate("your_file.xml") # or schema.is_valid("your_file.xml") # decode a file data = schmema.decode("your_file.xml") # encode to string s = etree_tostring(schema.encode(data)) This opinionated guide exists to provide both novice and expert Python developers a best practice handbook to the installation, configuration, and usage of Python on a daily basis.