我得到NRE錯誤,它說:「對象引用未設置爲對象的實例。」C#中的NullReferenceException處理XML
從下面的代碼:
select new
{
ICAO = station.Element("icao").Value,
};
整個腳本是:
XDocument xmlDoc = XDocument.Load(@"http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=94107");
var stations = from station in xmlDoc.Descendants("station")
select new
{
ICAO = station.Element("icao").Value,
};
lblXml.Text = "";
foreach (var station in stations)
{
lblXml.Text = lblXml.Text + "ICAO: " + station.ICAO + "<br />";
}
if (lblXml.Text == "")
lblXml.Text = "No Results.";
}
我不明白爲什麼不創建站對象並設置國際民航組織值。任何有關未來XML和C#參考的想法/提示?
爲什麼在ICAO = station.Element(「Icao」)之後有逗號?價值線?你沒有得到多個元素...... – curtisk 2009-06-30 16:04:28
它並沒有受到傷害,它可能是代碼的實際部分要大得多。如果這實際上完成了所有工作,那麼在新的{...}內也不需要它,您可以直接選擇icao。 – 2009-06-30 16:14:24