これは私のxmlデータへのリンクです
http://api.worldbank.org/countries/IND/indicators/EN.ATM.CO2E.PC?per_page=10&date=2005:2012
次のコードを使用して解析および表示していますが、実行できません。
public void Getinfo()
{
try
{
String url = http://api.worldbank.org/countries/IND/indicators/EN.ATM.CO2E.PC?per_page=10&date=2005:2012";
WebClient wc = new WebClient();
wc.OpenReadCompleted += wc_OpenReadCompleted;
wc.OpenReadAsync(new Uri(url));
}
catch (Exception)
{
MessageBox.Show("Please retry unable to access Data");
}
}
private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error + "");
return;
}
using (Stream s = e.Result)
{
XDocument doc = XDocument.Load(s);
XNamespace wb = "http://www.worldbank.org";
foreach (var node in doc.Element(wb+"data").Element(wb+"data").Elements(wb+"date"))
{
String chk = node.Value.ToString();
String year1 = "2007";
if (chk == year1)
{
foreach (var node1 in doc.Element(wb+"data").Element(wb+"data").Elements(wb+"value"))
{
info1.Text = node1.Value.ToString();
}
}