views:

33

answers:

1

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! :)

+4  A: 

Just document.RootElement.Elements() should work.

Basically Descendants() recurses, whereas Elements() only gets direct children.

Jon Skeet
Thank you, Jon! :)
podeig