Next / Previous / Contents / TCC Help System / NM Tech homepage

7. class ElementTree: A complete XML document

Once you have used the etree.ElementTree constructor to instantiate an XML document, you can use these attributes on methods on that instance.

7.1. ElementTree.find()

This method searches the tree for matching elements, and returns the first one that matches, or None if there are no matches. For an instance ET of an ElementTree:

ET.find ( path )

The path argument is a string describing the element for which you are searching. Possible values include:

"tag"

Find the first child element whose name is "tag".

"tag1/tag2/.../tagn"

Find the first child element whose name is tag1; then, under that child element, find its first child named tag2; and so forth.

For example, suppose you have an ElementTree instance named page, containing an XHTML page. Further suppose you want to find the link element inside the head element inside the root html element. This statement would set the variable linkElt to that link element:

linkElt = page.find ( "html/head/link" )