[PHP] xpath question

2008-02-19 Thread RJO
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
PlacemarkerLineStringcoordinates element.


The problem I am having is that sometimes the KML file can have a
documentfolder or folderdocument 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
namecoehilltotweed.kml/name
Style id=lineStyle
LineStyle
color6417/color
width6/width
/LineStyle
/Style
Folder
name23-SEP-06/name
Snippet maxLines=2
/Snippet
description![CDATA[table
trtdbDistance/b 139.0 mi /td/tr
trtdbMin Alt/b 451.4 ft /td/tr
trtdbMax Alt/b 1168.9 ft /td/tr
  /table]]/description
Placemark
namePath/name
styleUrl#lineStyle/styleUrl
LineString
tessellate1/tessellate
coordinates
-77.827985,44.851878,311.109985
-77.827021,44.852114,313.993896
-77.827213,44.8506760001,313.513306
-77.827792,44.850955,313.513306
-77.830389,44.8533370001,315.916504
-77.833114,44.858379,317.358643
-77.8319330001,44.858508,313.993896 /coordinates
/LineString
/Placemark
/Folder
/Document
/kml

Any ideas why this won't work?

Thanks!

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



Re: [PHP] xpath question

2008-02-19 Thread Andrew Ballard
On Feb 19, 2008 8:13 PM, RJO [EMAIL PROTECTED] 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
 PlacemarkerLineStringcoordinates element.


 The problem I am having is that sometimes the KML file can have a
 documentfolder or folderdocument 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
namecoehilltotweed.kml/name
Style id=lineStyle
LineStyle
color6417/color
width6/width
/LineStyle
/Style
Folder
name23-SEP-06/name
Snippet maxLines=2
/Snippet
description![CDATA[table
trtdbDistance/b 139.0 mi /td/tr
trtdbMin Alt/b 451.4 ft /td/tr
trtdbMax Alt/b 1168.9 ft /td/tr
  /table]]/description
Placemark
namePath/name
styleUrl#lineStyle/styleUrl
LineString
tessellate1/tessellate
coordinates
 -77.827985,44.851878,311.109985
 -77.827021,44.852114,313.993896
 -77.827213,44.8506760001,313.513306
 -77.827792,44.850955,313.513306
 -77.830389,44.8533370001,315.916504
 -77.833114,44.858379,317.358643
 -77.8319330001,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



Re: [PHP] xpath question

2008-02-19 Thread Nick Stinemates
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
 PlacemarkerLineStringcoordinates element.


 The problem I am having is that sometimes the KML file can have a
 documentfolder or folderdocument 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
 namecoehilltotweed.kml/name
 Style id=lineStyle
 LineStyle
 color6417/color
 width6/width
 /LineStyle
 /Style
 Folder
 name23-SEP-06/name
 Snippet maxLines=2
 /Snippet
 description![CDATA[table
 trtdbDistance/b 139.0 mi /td/tr
 trtdbMin Alt/b 451.4 ft /td/tr
 trtdbMax Alt/b 1168.9 ft /td/tr
   /table]]/description
 Placemark
 namePath/name
 styleUrl#lineStyle/styleUrl
 LineString
 tessellate1/tessellate
 coordinates
 -77.827985,44.851878,311.109985
 -77.827021,44.852114,313.993896
 -77.827213,44.8506760001,313.513306
 -77.827792,44.850955,313.513306
 -77.830389,44.8533370001,315.916504
 -77.833114,44.858379,317.358643
 -77.8319330001,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



[PHP] XPath question

2007-02-05 Thread Eli

Hi,

ns:root i=0
tag
ns:node i=1/
/tag
ns:anothernode i=2
ns:notme i=3
ns:meneither i=4/
/ns:notme
anothertag/
/ns:anothernode
/ns:root

I need to retrieve a list of all the INNER ns:* nodes (not the root 
i=0 node), that do not have an ancestor of any ns:* node but the root 
ns:root i=0 node.

In other words: get all ns:* nodes with i in {1,2}.

-thanks!

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



[PHP] xpath question

2006-06-29 Thread bruce
hi...

in getting information on xpath/xml.. i thought i'd ask these lists as
well...

i'm trying to find out if there's a tool that i could use to load an HTML
web page into, that would allow me to point to a given item/element within
the Tree/DOM structure and allow me to see what the Xpath statement would be
to generate that given itm/element of the Tree...

i've seen a few tools but none that have exactly what i'm looking for...

has anyone knowledge of any kind of tool/plugin like this? i'd also like to
hear your comments pro/con of the tool if you've actually used it!!

thanks

-bruce

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