Multi Level Descendants
-
Hi, I have recursive XML (an object containing 1 or more instances of his own type) and I want to get the Descendants of my current node but exclude the sub-nodes, how would I do that? Here's my XML:
<BodyItem>
<Fields>
<Field Name="Second 1" >1</Field>
<Field Name="Second 2" >2</Field>
</Fields>
<BodyItems>
<BodyItem >
<Fields>
<Field Name="Field3" IsReadOnly="false"></Field>
</Fields>
</BodyItem>
</BodyItems>
</BodyItem>From the above XML I would like to get Fields "Second 1" and "Second 2", but exclude "Field3"
____________________________________________________________ Be brave little warrior, be VERY brave
-
Hi, I have recursive XML (an object containing 1 or more instances of his own type) and I want to get the Descendants of my current node but exclude the sub-nodes, how would I do that? Here's my XML:
<BodyItem>
<Fields>
<Field Name="Second 1" >1</Field>
<Field Name="Second 2" >2</Field>
</Fields>
<BodyItems>
<BodyItem >
<Fields>
<Field Name="Field3" IsReadOnly="false"></Field>
</Fields>
</BodyItem>
</BodyItems>
</BodyItem>From the above XML I would like to get Fields "Second 1" and "Second 2", but exclude "Field3"
____________________________________________________________ Be brave little warrior, be VERY brave
I think I have found the answer (so soon :-D ), this worked for me, is it the correct way?
var fields = (from bif in bodyItemNode.Elements("Fields").Descendants("Field")
____________________________________________________________ Be brave little warrior, be VERY brave