RJO wrote:
> Hey guys,
>
> I have a form accepting a KML file from users and from there I want to
> draw polylines based on a KML file's
> <Placemarker><LineString><coordinates> element.
>
>
> The problem I am having is that sometimes the KML file can have a
> <document><folder> or <folder><document> or none of the above, or any
> number of random scenarios in the KML file making it hard to parse.
>
>
> To deal with this randomness I'm using an xpath and I think I have it
> right but it just wont work... the code:
> $result = $xml->xpath('Placemark/LineString/coordinates');
>
>
> An the particular XML file I am trying to pull from looks like:
> <?xml version="1.0" encoding="UTF-8"?>
> <kml xmlns="http://earth.google.com/kml/2.1";>
> <Document>
>         <name>coehilltotweed.kml</name>
>         <Style id="lineStyle">
>                 <LineStyle>
>                         <color>64eeee17</color>
>                         <width>6</width>
>                 </LineStyle>
>         </Style>
>         <Folder>
>                 <name>23-SEP-06</name>
>                 <Snippet maxLines="2">
>                 </Snippet>
>                 <description><![CDATA[<table>
>             <tr><td><b>Distance</b> 139.0 mi </td></tr>
>             <tr><td><b>Min Alt</b> 451.4 ft </td></tr>
>             <tr><td><b>Max Alt</b> 1168.9 ft </td></tr>
>           </table>]]></description>
>                 <Placemark>
>                         <name>Path</name>
>                         <styleUrl>#lineStyle</styleUrl>
>                         <LineString>
>                                 <tessellate>1</tessellate>
>                                 <coordinates>
> -77.827985,44.851878,311.109985
> -77.82702000000001,44.852114,313.993896
> -77.827213,44.85067600000001,313.513306
> -77.827792,44.850955,313.513306
> -77.830389,44.85333700000001,315.916504
> -77.833114,44.858379,317.358643
> -77.83193300000001,44.858508,313.993896 </coordinates>
>                         </LineString>
>                 </Placemark>
>         </Folder>
> </Document>
> </kml>
>
> Any ideas why this won't work?
>
> Thanks!
>
>   
If you're just trying to get the coordinates, you can use:

$result = $xml->xpath('//coordinates');

I have a feeling you'll want to do more parsing than that, thought.

In the case of your example, I believe it should be the following:

$result = $xml->xpath('Folder/Placemark/LineString/coordinates'); _or_

$result = $xml->xpath('Document/Folder/Placemark/LineString/coordinates'); 

I can never remember. One of those 2 will work.

-- 
==================
Nick Stinemates ([EMAIL PROTECTED])
http://nick.stinemates.org

AIM: Nick Stinemates
MSN: [EMAIL PROTECTED]
Yahoo: [EMAIL PROTECTED]
==================

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to