开发者

How to get one level in XML by linq

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"开发者_C百科 />
    <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.

:)


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜