【发布时间】:2010-03-06 01:54:38
【问题描述】:
我可能遗漏了一些明显的东西,但在我的 Linq to 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
};
我整天都在看这个并尝试了很多东西,但没有运气。有人可以帮助这个密集的程序员吗?
【问题讨论】:
标签: c# linq-to-xml