开发者

How to get first level of children by LINQ

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜