CHAPTER 12 ■ XML
194
Searching for Nodes Within an XML Document
So far, we’ve worked with this XML document “from the top down,” starting with the root element,
getting its child elements, and so on throughout the document. But many uses of XML require you to
find specific elements. The ElementTree API can do that, too. (See Listing 12-18.)
Listing 12-18. Searching for Specific Eelements
>>> import xml.etree.ElementTree as etree
>>> tree = etree.parse('examples/feed.xml')
>>> root = tree.getroot()
>>> root.findall('{http://www.w3.org/2005/Atom}entry') (1)
[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>,
<Element {http://www.w3.org/2005/Atom}entry at e2b510>,
<Element {http://www.w3.org/2005/Atom}entry at e2b540>]
>>> root.tag ...