我收到以下错误:
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>>' to 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>'. An explicit conversion exists (are you missing a cast?)
我不明白为什么。在这里,您有我的代码,我在其中尝试获取属性与以下相同的DataContainer
元素:Name
name.key
XDocument xml = XDocument.Load(name.Value);
IEnumerable<XElement> columns = from d in xml.Descendants("DataContainer")
where (d.Attribute("Name").Value.Equals(name.Key))
select d.Descendants("ArrayOfColumn");
这里有我的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<DataContainers>
<DataContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="IRS vs E3M" Currency="EUR">
<ArrayOfColumn Name="Maturite" isData="false">
<Line Value="1Y" />
<Line Value="2Y" />
<Line Value="3Y" />
<Line Value="4Y" />
<Line Value="5Y" />
<Line Value="6Y" />
<Line Value="7Y" />
<Line Value="8Y" />
<Line Value="9Y" />
<Line Value="10Y" />
<Line Value="15Y" />
<Line Value="20Y" />
<Line Value="30Y" />
<Line Value="40Y" />
<Line Value="50Y" />
<Line Value="60Y" />
</ArrayOfColumn>
<ArrayOfColumn Name="Value" isData="true">
<Line Value="EURAB3E1Y" />
<Line Value="EURAB3E2Y" />
<Line Value="EURAB3E3Y" />
<Line Value="EURAB3E4Y" />
<Line Value="EURAB3E5Y" />
<Line Value="EURAB3E6Y" />
<Line Value="EURAB3E7Y" />
<Line Value="EURAB3E8Y" />
<Line Value="EURAB3E9Y" />
<Line Value="EURAB3E10Y" />
<Line Value="EURAB3E15Y" />
<Line Value="EURAB3E20Y" />
<Line Value="EURAB3E30Y" />
<Line Value="EURAB3E40Y" />
<Line Value="EURAB3E50Y" />
<Line Value="EURAB6E60Y" />
</ArrayOfColumn>
</DataContainer>
</DataContainers>
有人可以帮助我并解释为什么吗?