开发者

Get child elements from XElement [duplicate]

开发者 https://www.devze.com 2023-01-12 23:36 出处:网络
This question already has answers here: 开发者_运维百科 Closed 11 years ago. Possible Duplicate: Children of XElement
This question already has answers here: 开发者_运维百科 Closed 11 years ago.

Possible Duplicate:

Children of XElement

I want to get child elements from XElement using C#. How can this be done?


Try .Elements() :

XElement element = GetElement();
var children = element.Elements();

If you want elements from all levels, you may also have a look at Descendants.


There are a few alternatives to navigate from an XElement to its children:

IEnumerable<XElement> allChildElements = xElement.Elements();
IEnumerable<XElement> specificChildElements = xElement.Elements("tag");
XElement firstSpecificChildElement = xElement.Element("tag");
0

精彩评论

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

关注公众号