title: Parsing Google Earth KML file in Python (lxml, namespaces)
body: <p>I am trying to parse a <a href="https://developers.google.com/kml/documentation/" rel="nofollow">.kml</a> file into Python using the xml module (after failing to make this work in BeautifulSoup, which I use for HTML). </p>
  
  <p>As this is my first time doing this, I followed the official <a href="http://lxml.de/1.3/tutorial.html" rel="nofollow">tutorial</a> and all goes well until I try to construct an iterator to extract my data by root iteration:</p>
  
  <pre><code>from lxml import etree
  tree=etree.parse('kmlfile')
  </code></pre>
  
  <p>Here is the <a href="http://lxml.de/1.3/tutorial.html#tree-iteration" rel="nofollow">example</a> from the tutorial I am trying to emulate:</p>
  
  <blockquote>
    <p>If you know you are only interested in a single tag, you can pass its name to getiterator() to have it filter for you:  </p>
  
  <pre><code>for element in root.getiterator("child"):
      print element.tag, '-', element.text
  </code></pre>
  </blockquote>
  
  <p>I would like to get all data under 'Placemark', so  I tried</p>
  
  <pre><code>for i in tree.getiterterator("Placemark"):
      print i, type(i)
  </code></pre>
  
  <p>which doesn't give me anything. What does work is:</p>
  
  <pre><code>for i in tree.getiterterator("{http://www.opengis.net/kml/2.2}Placemark"):
      print i, type(i)
  </code></pre>
  
  <p>I don't understand how this comes about. The www.opengis.net is listed in the  tag at the beginning of the document (<em>kml xmlns="http://www.opengis.net/kml/2.2"...</em>) , but I don't understand </p>
  
  <ul>
  <li><p>how the part in {} relates to my specific example at all</p></li>
  <li><p>why it is different from the tutorial</p></li>
  <li>and what I am doing wrong</li>
  </ul>
  
  <p>Any help is much appreciated!</p>