There is a question that does almost exactly what I want to do by almost the same name, however I don’t know what my XML DOM will look like ahead of time.
I would like to do something like this:
private static IEnumerable<XElement> FindAllContainers(XDocument xml)
{
IEnumerable<XElement> query = from XElement outer in xml.Root.Elements()
from XElement node in outer.Elements()
where true //Enum.IsDefined(typeof(Role), GetContainerRole(node))
select node;
return query;
}
The basic Idea is I want to query against an enumeration of all XElements for any given XML structure. The above code doesn’t return any results. With xml containing a large nested XML structure and being an XDocument. The other question manually supplies Elements with the tag names. I don’t know what they are ahead of time to set it up statically in the method.
So it sounds to me like you just want to enumerate through all elements within the document. Well nothing complicated here, just call the
Descendants()method (with no arguments) and it will return all elements within the document.