Rahul Singh

Rahul Singh

  • NA
  • 1.4k
  • 584.6k

How to Traverse up in LINQ-XML?

Jan 16 2015 12:22 PM
I have a big XML file and suppose I have following code:-
 
xdoc.Descendants("employee").Select(x => //rest of the code
 
Suppose I have multiple nodes in between, now I want to traverse back to root node with this element i.e. `x`
So currently doing it like this:-
 
x.Parent.Parent.Parent
 
I want to know is their any alternative to this? So that I can directly reach the root element? 
 
 

Answers (2)