title: Parsing XML in Python and my 'NodeList' object has no attribute 'len'
body: <p>I'm very new to Python and trying to write a program that parses some XML. I'm having the issue where when I attempt to call <code>.len()</code> on what I believe to be a NodeList I get the error <code>'NodeList' object has no attribute 'len'</code>. This is really surprising to me because the <a href="http://docs.python.org/library/xml.dom.html" rel="nofollow">documentation</a> says:</p>
  
  <blockquote>
    <p>In addition, the Python DOM interface requires that some additional support is provided to  allow NodeList objects to be used as Python sequences. All NodeList implementations must include support for <strong>len</strong>()</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>import xml.dom.minidom
  
  def testFunction(translationDOM):
      textCollection = translationDOM.getElementsByTagName("onscreen_text")
      for onscreenText in textCollection:
          print textCollection.len()
  </code></pre>
  
  <p>and then in the <code>Main()</code>...</p>
  
  <pre><code>translationDom  = parse(xmlFileName)
  testFunction(translationDom)
  </code></pre>
  
  <p>I don't want to post my entire xml here (its massive), but there's a number of blocks similar to:</p>
  
  <pre><code>&lt;onscreen_text&gt;
      &lt;source id="2036" unique_name="blah" should_be_translated="True"&gt;
      ....
   &lt;/onscreen_text&gt;
  </code></pre>
  
  <p>Here's the full error text:</p>
  
  <pre><code>  File "trophytool.py", line 155, in &lt;module&gt;
      main()
    File "trophytool.py", line 134, in main
      testFunction(translationDom)
    File "trophytool.py", line 64, in testFunction
      print textCollection.len()
  AttributeError: 'NodeList' object has no attribute 'len'
  </code></pre>
  
  <p>You'd think it would print the number of <code>&lt;onscreen_text&gt;</code> tags it finds, but it doesn't. Why is this?</p>