我可能錯過了一些明顯的東西,但是我在Linq to xml查詢中得到'對象引用未設置爲對象的實例'null錯誤。linq到xml的問題
這裏是XML
<airport>
<station>
<city>Rutland</city>
<state>VT</state>
<country>US</country>
<icao>KRUT</icao>
<lat>43.52999878</lat>
<lon>-72.94999695</lon>
</station>
</airport>
這裏的樣本是我的查詢
XDocument geoLocation = XDocument.Load("myTestGeo.xml");
var currLocation = from geo in geoLocation.Descendants("airport")
select new
{
City = geo.Element("city").Value,
State = geo.Element("state").Value,
Country = geo.Element("country").Value,
Station = geo.Element("icao").Value
Lat = geo.Element("lat").Value,
Lon = geo.Element("lon").Value
};
我一直在尋找這一切的一天,想很多東西,但沒有運氣。有人可以幫助這個密集的程序員嗎?
我看到了,但如果我站上查詢我得到同樣的錯誤無效。 – 2010-03-05 17:55:26
我沒有.net框架與linq,所以我不能測試自己。請參閱http://www.linqhelp.com/linq-tutorials/linq-to-xml-displaying-and-filtering-data-from-xml-file-in-c/,這個例子與您所看到的非常相似試圖實現。 – 2010-03-05 18:05:18
你確定'myTestGeo.xml'具有你在這個例子中指出的XML嗎? – 2010-03-05 18:07:52