For an XDocument descendant operation, can only immediate child nodes be returned?

For an XDocument descendant operation, can only immediate child nodes be returned?

I have a row operation:

XDocument xmlDc = XDocument.Load(dependencyFilePath); IEnumerable<IGrouping<string, XElement>> scriptNodes = from s in xmlDc.Descendants("script") select s; 

The problem is that my XML document is structured as follows

 <topNode> <script> <someNode>...</someNode> <script>....</script> </script> </topNode> 

Essentially, script tags can have tags for children, but when I do Descendents, I only want to get the children of the node, not the grandson of the script.

Is this possible with XDocument? Can I use the predicate to somehow check if the potential breeder has a parent node that I check to accomplish this?

+7
c # linq-to-xml
source share
1 answer

I think Elements("script") will do the trick instead of Descendants("script")

+16
source share

All Articles