C# XML, find node and all his parents

outlawriderz

New Member
I got an XML structure like:\[code\]<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>\[/code\]From C# Linq to XML, get parents when a child satisfy conditionI got something like this:\[code\]XElement doc = XElement.Load("path");var result = doc.Elements("siteNode").Where(parent => parent.Elements("siteNode").Any(child => child.Attribute("action").Value =http://stackoverflow.com/questions/11412029/= ActionName && child.Attribute("controller").Value =http://stackoverflow.com/questions/11412029/= ControlerName));\[/code\]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:\[code\]<siteNode controller="eee" action="fff" title="" /> with parent <siteNode controller="cc" action="dd" title="" >with parent<siteNode controller="a" action="b" title="" >\[/code\]Obvious answer is to use that linq expression on found parent until it's null, but is there any better (cleaner) way?
 
Back
Top