Try using <tt class="descname">getroot</tt><big>(</big><big>)</big><a class="headerlink" href="http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.getroot" title="Permalink to this definition"></a><div>
<span class="Apple-style-span" style="font-size: 16px;"><br></span></div><div><span class="Apple-style-span" style="font-size: 16px;">I think your root is components so its searching in root <br></span><br><div class="gmail_quote">
On Tue, Aug 31, 2010 at 2:19 PM, Brendan Simon (eTRIX) <span dir="ltr"><<a href="mailto:brendan.simon@etrix.com.au">brendan.simon@etrix.com.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


  

    
  
  <div 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>
  </div>

<br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Nitin Pawar<br><br>
</div>