I know I can do this iteratively, but it would be cool to do it in a single LINQ statement.
I have some XML that looks like this:
<parent name="george">
<child name="steve" age="10" />
<child name="sue" age="3" />
<pet type="dog" />
<child name="jill" age="7" />
</parent>
<!-- ... -->
and I want to write a LINQ to XML statement to turn it into
<node type="parent" label="george">
<node type="child" label="steve" years="10 />
<node type="child" label="sue" years="3" />
<node type="child" label="jill" years="7" />
<!-- no pets! -->
</parent>
<!-- ... -->
Is that possible in a single LINQ to XML statement?
I’ve included two from statements in a LINQ statement before, but not a second select, which seems to be what this would require.
You’ll need to query the desired elements and create new elements and attributes using the queried items. Something like this should work: