I got an XML structure like:
<siteNode controller="a" action="b" title="">
<siteNode controller="aa" action="bb" title="" />
<siteNode controller="cc" action="dd" title="">
<siteNode controller="eee" action="fff" title="" />
</siteNode>
</siteNode>
From C# Linq to XML, get parents when a child satisfy condition
I got something like this:
XElement doc = XElement.Load("path");
var result = doc.Elements("siteNode").Where(parent =>
parent.Elements("siteNode").Any(child => child.Attribute("action").Value ==
ActionName && child.Attribute("controller").Value == ControlerName));
Which returns my node and its parent. How could I get not only the parent of the node but also its "grandparents", I mean the parent of the parent etc. So with my XML it would be:
<siteNode controller="eee" action="fff" title="" />
with parent
<siteNode controller="cc" action="dd" title="" >
with parent
<siteNode controller="a" action="b" title="" >
Obvious answer is to use that linq expression on found parent until it's null, but is there any better (cleaner) way?