Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag for United States of America

asked on

Xpath

I have a web service that is returning this:

<?xml version="1.0" encoding="utf-16"?>
<GeocodeInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Latitude xmlns="http://tempuri.org/">42.0903</Latitude>
  <Longitude xmlns="http://tempuri.org/">-71.423011</Longitude>
  <AddressID xmlns="http://tempuri.org/">27195</AddressID>
</GeocodeInfo>


I am trying to extract the latitude like this but I am not getting any value

sLatitude = xdoc.SelectNodes("/Latitude")

Can someone help me with this.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
a better way is to use a namespace mannager

XmlNamespaceManager manager = new XmlNamespaceManager(xdoc.NameTable);
manager.AddNamespace("tmp", "http://tempuri.org/");

sLatitude = xdoc.SelectNodes("//tmp:Latitude")

this way you bind the "tmp:" prefix to the tempuri namespace first
and then you use the prefix in teh XPath