从XML填充列表<>响应
问题描述:
我的问题是我怎么能达到从XML填充列表<>响应
<xml>
<item>
<eventid>1</eventid>
<eventname>Test</eventname>
<startdate>2012-04-30 12:00:00</startdate>
<locationid>
<locationid>1</locationid>
<city>Amsterdam</city> <-----------This field
<venuename>Java-eiland</venuename>
</locationid>
</item>
</xml>
却使列表
eventInfo = (from item in events.Descendants("item")
select new Event
{
EventId = Convert.ToInt16(item.Element("eventid").Value),
EventName = item.Element("eventname").Value,
EventCity = ??????????
}).ToList();
我发现Using LINQ to fill a List<object> from xml 但他们没有深入研究XML就像我想要做的
在此先感谢
答
item.Element("locationid").Element("city").Value
+0
哇,我现在觉得很愚蠢,我没有尝试过。但非常感谢:D – MrME 2012-04-10 13:58:58
只需在locationid上调用.element即可降至下一级别。 – 2012-04-10 13:44:58