title: Inspect and Parse KML with pyKML
body: <p>similar to this: <a href="https://stackoverflow.com/questions/13712132/extract-coordinates-from-kml-batchgeo-file-with-python">Extract Coordinates from KML BatchGeo File with Python</a></p>
  
  <p>But I want to know how to inspect the data object, as well as how to iterate it, and parse all the <code>Placemark</code> to get the <code>coordinates</code>.</p>
  
  <p>The below is the how the KML looks like, and there are multiple <code>&lt;Placemark&gt;</code> tags.</p>
  
  <p><strong>Sample KML data</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd"&gt;
  &lt;Document id="..."&gt;
    &lt;name&gt;...&lt;/name&gt;
    &lt;Snippet&gt;&lt;/Snippet&gt;
    &lt;Folder id="..."&gt;
      &lt;name&gt;...&lt;/name&gt;
      &lt;Snippet&gt;&lt;/Snippet&gt;
      &lt;Placemark id="..."&gt;
        &lt;name&gt;....&lt;/name&gt;
        &lt;Snippet&gt;&lt;/Snippet&gt;
        &lt;description&gt;...&lt;/description&gt;
        &lt;styleUrl&gt;....&lt;/styleUrl&gt;
        &lt;Point&gt;
          &lt;altitudeMode&gt;...&lt;/altitudeMode&gt;
          &lt;coordinates&gt; 103.xxx,1.xxx,0&lt;/coordinates&gt;
        &lt;/Point&gt;
      &lt;/Placemark&gt;
      &lt;Placemark id="..."&gt;
        ...
      &lt;/Placemark&gt;
    &lt;/Folder&gt;
    &lt;Style id="..."&gt;
      &lt;IconStyle&gt;
        &lt;Icon&gt;&lt;href&gt;...&lt;/href&gt;&lt;/Icon&gt;
        &lt;scale&gt;0.250000&lt;/scale&gt;
      &lt;/IconStyle&gt;
      &lt;LabelStyle&gt;
        &lt;color&gt;00000000&lt;/color&gt;
        &lt;scale&gt;0.000000&lt;/scale&gt;
      &lt;/LabelStyle&gt;
      &lt;PolyStyle&gt;
        &lt;color&gt;ff000000&lt;/color&gt;
        &lt;outline&gt;0&lt;/outline&gt;
      &lt;/PolyStyle&gt;
    &lt;/Style&gt;
  &lt;/Document&gt;
  &lt;/kml&gt;
  </code></pre>
  
  <p>This is what I have, <strong>extract.py</strong>:</p>
  
  <pre class="lang-py prettyprint-override"><code>from pykml import parser
  from os import path
  
  kml_file = path.join('list.kml')
  
  with open(kml_file) as f:
    doc = parser.parse(f).getroot()
  
  print doc.Document.Folder.Placemark.Point.coordinates
  </code></pre>
  
  <p>This prints the first <code>coordinates</code>.</p>
  
  <p>General python question:<br>
  How can I inspect <code>doc</code>, find out about its type, and print out the values it contains?</p>
  
  <p>Task question:
  How do I iterate through all the <code>Placemark</code> and get its <code>coordinates</code>?</p>
  
  <p>Have tried the following but nothing is printed.</p>
  
  <pre class="lang-py prettyprint-override"><code>for e in doc.Document.Folder.iter('Placemark'):
     print e
  </code></pre>