Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
Xml 如何选择子节点而不是该子元素的整个子元素_Xml_Linq To Xml - Fatal编程技术网

Xml 如何选择子节点而不是该子元素的整个子元素

Xml 如何选择子节点而不是该子元素的整个子元素,xml,linq-to-xml,Xml,Linq To Xml,上面的代码返回category中属性为“Arts”的所有category元素 我想要的只是类别中属性为“Arts”的类别下方的节点 不属于文字属性设计和视觉艺术类。我想整个类别节点像下面 xDoc.Descendants("category").Where(a => a.Attribute("text").Value == "Arts").Descendants("category") 给你,希望你还需要这个: <category> <category tex

上面的代码返回category中属性为“Arts”的所有category元素 我想要的只是类别中属性为“Arts”的类别下方的节点 不属于文字属性设计和视觉艺术类。我想整个类别节点像下面

xDoc.Descendants("category").Where(a => a.Attribute("text").Value == "Arts").Descendants("category")

给你,希望你还需要这个:

 <category>
    <category text="Design"/>
    <category text="Visual Arts"/>
 <category>
 <category>
    <category text="Design"/>
    <category text="Visual Arts"/>
 <category>
    string category = "Business";
    var children = xDoc.Root.Elements("category").Where(a => a.Attribute("text").Value == category).Elements();