I'm having a bit of trouble getting XPath expressions to work to select nodes.
I am working with the google maps results.
A shortened example xml:
[code=xml]
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.co m/kml/2.0">
<Document>
<Placemark>
<name>Route</name>
<description>
<![CDATA[ Distance: 2,164 mi (about 1 day 7 hours)<br/>Map data ©2009 Sanborn, Tele Atlas ]]>
</description>
</Placemark>
</Document>
</kml>
[/code]
Now really there is a lot more to that xml, but what I am concerned with is the <Placemark> node that has the name of "Route", and then I want the contents of the description node.
After populating an XmlDocument doc, I tried to use this:
doc.SelectSingl eNode("/kml/Document/placemark[name='route']/description");
and
doc.SelectNodes ("/kml/Document/placemark[name='route']/description");
They always turn up no results.
I even tried:
doc.SelectNodes ("//description");
which also produced no results.
I was able to get it by using a non-xpath expression:
doc.ChildNodes[1].ChildNodes[0].LastChild["descriptio n"];
But seems very unstable as it relies on those indexes existing.
Does anyone know what is wrong with the XPath I used? Is it a namespace issue (I set up no namespaces)?
I am working with the google maps results.
A shortened example xml:
[code=xml]
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.co m/kml/2.0">
<Document>
<Placemark>
<name>Route</name>
<description>
<![CDATA[ Distance: 2,164 mi (about 1 day 7 hours)<br/>Map data ©2009 Sanborn, Tele Atlas ]]>
</description>
</Placemark>
</Document>
</kml>
[/code]
Now really there is a lot more to that xml, but what I am concerned with is the <Placemark> node that has the name of "Route", and then I want the contents of the description node.
After populating an XmlDocument doc, I tried to use this:
doc.SelectSingl eNode("/kml/Document/placemark[name='route']/description");
and
doc.SelectNodes ("/kml/Document/placemark[name='route']/description");
They always turn up no results.
I even tried:
doc.SelectNodes ("//description");
which also produced no results.
I was able to get it by using a non-xpath expression:
doc.ChildNodes[1].ChildNodes[0].LastChild["descriptio n"];
But seems very unstable as it relies on those indexes existing.
Does anyone know what is wrong with the XPath I used? Is it a namespace issue (I set up no namespaces)?
Comment