【发布时间】:2010-04-08 14:05:37
【问题描述】:
我想知道是否有一种方法可以将结果列表放入带有 linq to xml 的列表中。例如,如果我有以下 xml:
<?xml version="1.0"?>
<Sports xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SportPages>
<SportPage type="test">
<LinkPage>
<IDList>
<string>1</string>
<string>2</string>
</IDList>
</LinkPage>
</SportPage>
</SportPages>
</Sports>
如何从 IDList 中获取字符串列表?
我对 linq to xml 还很陌生,所以我只是尝试了一些东西,我目前处于这一点:
var IDs = from sportpage in xDoc.Descendants("SportPages").Descendants("SportPage")
where sportpage.Attribute("type").Value == "Karate"
select new
{
ID = sportpage.Element("LinkPage").Element("IDList").Elements("string")
};
但是 var 读起来很混乱。有没有办法可以从中获取字符串列表?
谢谢
【问题讨论】:
标签: c# xml linq list linq-to-xml