<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    I am trying to use ElementTree (with Python 2.7) and can't seem to
    find elements at the top level.  The find() and findall() methods
    seem to find elements within the top level, but not if it the
    elements are at the top level.<br>
    <br>
    How do I find top level elements ??<br>
    Here is my code.<br>
    <br>
    <blockquote><tt>import xml.etree.ElementTree as ET<br>
        <br>
        xml = '''\<br>
        <?xml version="1.0" encoding="Windows-1252" ?><br>
        <components><br>
          <component><br>
            <name>Fred</name><br>
            <location>Australia</location><br>
          </component><br>
        </components><br>
        '''<br>
        <br>
        root = ET.fromstring( xml )<br>
        <br>
        ### This pattern is not found :(<br>
        comps = root.find( './/components' )<br>
        <br>
      </tt><tt>### These patterns are found ok :)</tt><br>
      <tt>comp = root.find( './/component' )<br>
      </tt><tt>name = root.find( './/name' )<br>
      </tt><br>
      <tt>print 'comps =', comps<br>
        print 'comp =', comp<br>
      </tt><tt>print 'name =', name</tt><br>
    </blockquote>
    <br>
    Thanks, Brendan.<br>
    <br>
  </body>
</html>