這在Windows 7解析的XML數據的鏈接,我的XML數據的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();
}
}
實際問題是什麼?說你不能這樣做不會有太多的事情要繼續下去。 – 2012-04-23 15:48:21
我無法訪問xml文件中的所有值。我只能訪問第一個。 – 2012-04-23 16:51:57