Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get child elements from XElement [duplicate]

Tags:

Possible Duplicate:
Children of XElement

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

like image 918
CRK Avatar asked Aug 26 '10 10:08

CRK


2 Answers

Try .Elements() :

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

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

like image 158
Kobi Avatar answered Sep 28 '22 08:09

Kobi


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"); 
like image 26
Martin Liversage Avatar answered Sep 28 '22 10:09

Martin Liversage