I have 2 IEnumerables
IEnumerable<float> Distance
IEnumerable<XElement> Point
which i want to convert into
IEnumerable<Subsection> subsection
where the Class is
class Subsection
{
public float Distance
public XElement Point
}
But i have no idea how to do this, i have tried some variations of casting none of which has worked because they dont seem to accept multiple lists as inputs.
The Distance and Point variables are read from a xml document where the structure for these two points is similar to:
<PLI>
<Distance>5</Distance>
<Point>23 22</Point>
<Distance>7</Distance>
<Point>21 72</Point>
<Distance>9</Distance>
<Point>13 32</Point>
</PLI>
I wasn’t sure how to read them out simply as the subsection type but if anyone could suggest how to do that, it would bypass my need to convert it as i will no longer have them as IEnumerables of distance and point but as the structure.
Please note I cannot modify the XML
Thanks
EDIT: The XML has other elements as well as the ones mentioned within the PLI Tag e.g.
<PLI>
<OtherElement1>element1value</OtherElement1>
<OtherElement2>element2value</OtherElement2>
<Distance>5</Distance>
<Point>23 22</Point>
<Distance>7</Distance>
<Point>21 72</Point>
<Distance>9</Distance>
<Point>13 32</Point>
</PLI>
You can pull this off with LINQ with the help of the Enumerable.Zip method, provided your XML is balanced (an even number of elements to pair up distances and points).
Alternately, you could loop through the elements and build up the
Subsectionitems. This can be done as follows, although it assumes your XML document is balanced and in the expected format.Note that in both snippets the
xmlvariable is anXElement. For anXDocumentadd theRootproperty, as inxml.Root.Elements(...).