Re: xpath question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Feb 19, 2008 8:13 PM, RJO <rjo@xxxxxxxxx> 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!
>
>

It's the namespace. I'm not positive (I can't test on this computer)
but try this:

$result = $xml->xpath("*[local-name()='Placemark' and
namespace-uri()='http://earth.google.com/kml/2.1']/*[local-name()='LineString'
and namespace-uri()='http://earth.google.com/kml/2.1']/*[local-name()='coordinates'
and namespace-uri()='http://earth.google.com/kml/2.1']");

That may be a little off, but that's the idea, anyway.

Andrew

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux