tags:

views:

46

answers:

1

I have an XML

<item id="1">
    <item id="1.1">
        <item id="1.1.1" />
        <item id="1.1.2" />
        <item id="1.1.3" />
    </item>
    <item id="1.2" />
</item>
<item id="2">
    <item id="2.1" />
    <item id="2.2" />
    <item id="2.3" />
</item>
<item id="3" />

I need LINQ to get the first level, without children

<item id="1" />
<item id="2" />
<item id="3" />

or for item="1"

<item id="1.1" />
<item id="1.2" />

or for item="1.1" 

<item id="1.1.1" />
<item id="1.1.2" />
<item id="1.1.3" />

I build a menu, where I need to receive just nest level items.

:)

+2  A: 

Given an XElement, you can call the Elements() method to get its direct children. (You can ignore the grandchildren)

SLaks