Implicit conversion between XNode and XElement

I have two XResult, Xtemp variables of type XElement.

I am trying to extract all the elements <vehicle>from Xtemp and add them to Xresult's <vehicles>.

It seems that in Xtemp it <vehicle>will sometimes appear under <vehicles>, and sometimes it will by itself.

XResult.Descendants(xmlns + "Vehicles").FirstOrDefault().Add(
   XTemp.Descendants(xmlns + "Vehicles").Nodes().Count() > 0 
   ? XTemp.Descendants(xmlns + "Vehicles").Nodes() 
   : (XTemp.Descendants(xmlns + "SearchDataset").FirstOrDefault().Descendants(xmlns + "Vehicle")));

In the above code, I use the ternary operator to check if there are <vehicles>children, then all the rest to get all the elements <vehicle>.

This leads to an error: without an imperial conversion between System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode>andSystem.Collections.Generic.IEnumerable <System.Xml.Linq.XElement>

Can any body help me fix this. Thanks in advance. BB.

+3
source share
1 answer

, Nodes() Descendants(). . Nodes() IEnumerable<XNode>, Descendants() IEnumerable<XElement>. .

:

XTemp.Descendants(xmlns + "Vehicles").Nodes()

XTemp.Descendants(xmlns + "Vehicles").Nodes() 

Nodes() .

:, , . Descendants(xmlns + "Vehicle"):

.Descendants(xmlns + "Vehicle")
.SelectMany(d => d.DescendantNodesAndSelf().Take(1))

Take(1) node , , , .

+2

All Articles