Henk's answer should work, but I personally used
foreach (XElement xChild in xElem.Descendants())
where xElem will be equal to the parent for which you want all the children. Or you can also use the LINQ query to accomplish the same task.
var children = from xChild in xElem.Descendants() select Parse(xChild)
which should return an IEnumerable, which you can skip and add in this way.
EDIT:
It also became clear to me that you said you were new to C # without programming experience. I think it is also important that you understand why this error was thrown. In C #, to use a foreach loop, a collection must implement IEnumerable. This means that collection types can determine how data is listed. XElement is not enumerable because it means representing a single element, not a collection of elements. Therefore, the use of xElem.Element ("ElementName") is intended to return a single result, not an array or collection. Using xElem.Elements ("ElementName") will return a collection of all XElements that match the XName. However, if you want all the children of the same element regardless of the name, xElem.Descendants () is used here. Which one you use depends on what data you need and how to add it.
source share