Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用LINQ检索节点的描述和类别_C#_Linq - Fatal编程技术网

C# 使用LINQ检索节点的描述和类别

C# 使用LINQ检索节点的描述和类别,c#,linq,C#,Linq,我有以下标签 <NodeA desc="Household"> <NodeA desc="Cheap"> <NodeA desc="Cheap Item 1" category="Cooking" /> <NodeA desc="Cheap Item 2" category="Gardening" /> </NodeA> </NodeA> <NodeA> .

我有以下标签

<NodeA desc="Household">
    <NodeA desc="Cheap"> 
       <NodeA desc="Cheap Item 1" category="Cooking" />   
       <NodeA desc="Cheap Item 2" category="Gardening" />
    </NodeA>
 </NodeA>
 <NodeA> ...and so on
现在我想检索'desc'和'category'。我该怎么做呢?

像这样的。。。。(未经测试)


完全未经测试,但按照这些思路应该可以工作。

我如何使用Lamda exp做到这一点?不确定。。您可以尝试:(在上下文中从c中选择新的{Description=c.Attribute(“desc”),Category=c.Attribute(“Category”)});但那可能不是你想要的。
.Where(attr => attr.Name == "category")
.Select(attr => attr.Value);
from c in context
where c.Attribute("category") == "category name"
select new
{
  Description = c.Attribute("desc"),
  Category =  c.Attribute("category")
}