title: How to loop through Beautiful Soup elements to get attribute values
body: <p>I need to iterate over Beautiful Soup elements and get the attribute values:
  For a XML doc: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;Document&gt;
      &lt;Page x1="71" y1="120" x2="527" y2="765" type="page" chunkCount="25"
          pageNumber="1" wordCount="172"&gt;
          &lt;Chunk x1="206" y1="120" x2="388" y2="144" type="unclassified"&gt;
              &lt;Word x1="206" y1="120" x2="214" y2="144" font="Times-Roman" style="font-size:22pt"&gt;K&lt;/Word&gt;
              &lt;Word x1="226" y1="120" x2="234" y2="144" font="Times-Roman" style="font-size:22pt"&gt;O&lt;/Word&gt;
          &lt;/Chunk&gt;
       &lt;/Page&gt;
  &lt;/Document&gt;
  </code></pre>
  
  <p>I would like to get the x1 values of the "Word" elements (206,226).
  Help much appriciated!</p>
  
  <p>EDIT:
  I have tried:</p>
  
  <pre><code>for i in soup.page.chunk:
      i.word['x1']
  </code></pre>
  
  <p>that returns an error:</p>
  
  <pre><code>File "C:\Python26\lib\site-packages\BeautifulSoup.py", line 473, in __getattr__
      raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)
  AttributeError: 'NavigableString' object has no attribute 'word'
  </code></pre>
  
  <p>while:</p>
  
  <pre><code>soup.page.chunk.word['x1']
  </code></pre>
  
  <p>works correctly...and:</p>
  
  <pre><code>for i in soup.page.chunk:
      i.findNext(text=True)
  </code></pre>
  
  <p>gets the text form the element.</p>