Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.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到XML选择与模式匹配的子元素名称列表_C#_Linq To Xml - Fatal编程技术网

C# Linq到XML选择与模式匹配的子元素名称列表

C# Linq到XML选择与模式匹配的子元素名称列表,c#,linq-to-xml,C#,Linq To Xml,关于嵌套LINQ到XML查询的问题: 代码: 但这就产生了一个错误: 源类型为“System.Collections.Generic.IEnumerable”的查询表达式中的后续from子句中不允许使用类型为“System.Xml.Linq.XAttribute”的表达式。调用“SelectMany”时类型推断失败 只能对返回集合的表达式使用from。 .Attribute(“Name”)不返回集合,因此该行没有意义 你可能想要 let subSubResponse = subResponse.

关于嵌套LINQ到XML查询的问题:

代码: 但这就产生了一个错误:

源类型为“System.Collections.Generic.IEnumerable”的查询表达式中的后续from子句中不允许使用类型为“System.Xml.Linq.XAttribute”的表达式。调用“SelectMany”时类型推断失败


只能对返回集合的表达式使用
from

.Attribute(“Name”)
不返回集合,因此该行没有意义

你可能想要

let subSubResponse = subResponse.Attribute("Name")
或者只是

select subResponse.Attribute("Name").Value
我使用了您的“selectsubresponse.Attribute(“Name”).Value”,非常有效。谢谢
from subSubResponse in subResponse.Attribute("Name")
select subResponse.Value
let subSubResponse = subResponse.Attribute("Name")
select subResponse.Attribute("Name").Value