开发者

How to get one level in XML by linq

开发者 https://www.devze.com 2023-01-15 17:49 出处:网络
I have an XML <item id=\"1\"> <item id=\"1.1\"> <item id=\"1.1.1\" /> <item id=\"1.1.2\" />

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

精彩评论

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