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;
SelectSingleNode
always return a null value
Full stactrace:
at SingleScanPalletTag.MobileClient.ScanOutMenu.GetGeoLocation()
at SingleScanPalletTag.MobileClient.ScanOutMenu.button1_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)
at System.Windows.Forms.Form.ShowDialog()
at SingleScanPalletTag.MobileClient.Program.Main()
Can any one tell me how to get the country,latitude and longitude value from the above xml.
Please help me.