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.
精彩评论