title: PHP How to extract extended data from kml file
body: <p>I use the folowing PHP to extract the coordinates from a kml file: </p>
  
  <pre><code>$xml = simplexml_load_file('data.kml');
  $data = $xml-&gt;Document-&gt;Folder-&gt;Placemark;
  
  foreach ($data as $record) {
      $coordinates = $record-&gt;MultiGeometry-&gt;Polygon-&gt;outerBoundaryIs-&gt;LinearRing-&gt;coordinates[0];
  }
  </code></pre>
  
  <p>This works fine for the coordinates. But how can I Extact the ExtendedData? </p>
  
  <p>The kml file I am using:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kml xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.opengis.net/kml/2.2"&gt;
    &lt;Document&gt;
      &lt;name&gt;pc4_single_vlak&lt;/name&gt;
      &lt;visibility&gt;1&lt;/visibility&gt;
      &lt;Schema name="pc4_single_vlak" id="kml_schema_ft_pc4_single_vlak"&gt;
        &lt;SimpleField type="xsd:string" name="pc4"&gt;
          &lt;displayName&gt;pc4&lt;/displayName&gt;
        &lt;/SimpleField&gt;
        &lt;SimpleField type="xsd:string" name="woonplaats"&gt;
          &lt;displayName&gt;woonplaats&lt;/displayName&gt;
        &lt;/SimpleField&gt;
        &lt;SimpleField type="xsd:string" name="wplnaam_uniek"&gt;
          &lt;displayName&gt;wplnaam_uniek&lt;/displayName&gt;
        &lt;/SimpleField&gt;
        &lt;SimpleField type="xsd:string" name="gemeente"&gt;
          &lt;displayName&gt;gemeente&lt;/displayName&gt;
        &lt;/SimpleField&gt;
        &lt;SimpleField type="xsd:string" name="provincie"&gt;
          &lt;displayName&gt;provincie&lt;/displayName&gt;
        &lt;/SimpleField&gt;
      &lt;/Schema&gt;
      &lt;Folder id="kml_ft_pc4_single_vlak"&gt;
        &lt;name&gt;pc4_single_vlak&lt;/name&gt;
        &lt;Placemark id="kml_1"&gt;
          &lt;name&gt;kml_1&lt;/name&gt;
          &lt;snippet&gt;&lt;/snippet&gt;
          &lt;ExtendedData&gt;
            &lt;SchemaData schemaUrl="#kml_schema_ft_pc4_single_vlak"&gt;
              &lt;SimpleData name="pc4"&gt;4001&lt;/SimpleData&gt;
              &lt;SimpleData name="woonplaats"&gt;Tiel&lt;/SimpleData&gt;
              &lt;SimpleData name="wplnaam_uniek"&gt;Tiel&lt;/SimpleData&gt;
              &lt;SimpleData name="gemeente"&gt;Tiel&lt;/SimpleData&gt;
              &lt;SimpleData name="provincie"&gt;Gelderland&lt;/SimpleData&gt;
            &lt;/SchemaData&gt;
          &lt;/ExtendedData&gt;
          &lt;MultiGeometry&gt;
            &lt;Polygon&gt;
              &lt;outerBoundaryIs&gt;
                &lt;LinearRing&gt;
                  &lt;coordinates&gt;...&lt;/coordinates&gt;
                &lt;/LinearRing&gt;
              &lt;/outerBoundaryIs&gt;
            &lt;/Polygon&gt;
          &lt;/MultiGeometry&gt;
        &lt;/Placemark&gt;
      &lt;/Folder&gt;
    &lt;/Document&gt;
  &lt;/kml&gt;
  </code></pre>
  
  
  
  <p>I tried all kinds of things, but I cant get it to work.</p>