时间:2010-07-26 09:50:32

标签: linq linq-to-xml

4 个答案:

答案 0 :(得分:6)

答案 1 :(得分:1)

答案 2 :(得分:1)

答案 3 :(得分:0)

我知道现在这很古老了,但我认为解决这个问题的方法没有做必要的处理,而是看起来像这样:

mappings.Root.Elements()
        .Where(cm => cm.Attribute("name").Value == "modelY")
        .SelectMany(cm => cm.Elements()
                            .Where(m => m.Attribute("colour").Value == "White")
                            .SelectMany(m => m.Attributes()));

在查询格式中,它将是:

from cm in doc.Root.Elements()
where cm.Attribute("name").Value == "modelY"
from m in cm.Elements()
where m.Attribute("colour").Value == "White"
from att in m.Attributes()
select att;