XMLから特定の行を返そうとしています。
<geoip>
<source>smart-ip.net</source>
<host>68.9.63.33</host>
<lang>en</lang>
<countryName>United States</countryName>
<countryCode>US</countryCode>
<city>West Greenwich</city>
<region>Rhode Island</region>
<latitude>41.6298</latitude>
<longitude>-71.6677</longitude>
<timezone>America/New_York</timezone>
</geoip>
以前はフルダンプを取得していましたが、現在はこのコードを使用しています...
[送信]をクリックすると、これが表示null
されます。name
XML呼び出しを読み取らない理由がわかりません。
これが私のコードです...
try {
WebClient wc = new WebClient();
var xml = wc.DownloadString(string.Format("http://smart-ip.net/geoip-xml/",
txtIP.Text));
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var name = doc.DocumentElement.SelectSingleNode("//geoip/countryName").Value;
txtIPresults.Text = name;
} catch (Exception myException) {
throw new Exception("Error Occurred:", myException);
}