I have such XMl
<root>
<list>
<list>
<topic></topic>
<topic></topic>
</list>
<topic></topic>
<topic></topic>
</list>
<topic></topic>
<topic></topic>
<topic></topic>
</root>
I need to get the first level of children:
<list></list>
<topic></topic>
<topic></topic>
<topic></topic>
I try to do like this
var list = x.Descendants().Where(e => e.Name == "list" || e.Name == "topic");
But it returns all topics and lists.
Please help! :)
Just document.Root.Elements()
should work.
Basically Descendants()
recurses, whereas Elements()
only gets direct children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With