I am trying to get the country, lat/long, timezone etc from an api using public ip.
Below is the xml response i am getting from api,
<IPInformation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ws.cdyne.com/"> <City>Chennai</City> <StateProvince>25</StateProvince> <Country>India</Country> <Organization/> <Latitude>13.0833</Latitude> <Longitude>80.28329</Longitude> <AreaCode>0</AreaCode> <TimeZone/> <HasDaylightSavings>false</HasDaylightSavings> <Certainty>90</Certainty> <RegionName/> <CountryCode>IN</CountryCode> </IPInformation> I am loading the response in xml file, from there using SelectSingleNode i am trying to get the country value. But always i am getting nullreferenceexception.
Below is the code i have tried,
if (response.StatusCode.ToString().ToLower() == "ok") { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(response.GetResponseStream()); XmlNode msgnode = xmlDoc.DocumentElement.SelectSingleNode("//Country"); -->getting null here string msgname = msgnode.InnerText; } tried below one,
String country = xmlDoc.SelectSingleNode("IPInformation/Country").Value; Nothing worked,always i am getting nullreferenceexception while trying to get the country or other values from xml response.
Can any one tell me how to get the country,latitude and longitude value from the above xml.
Please help me.
No comments:
Post a Comment