2
Answers

How to Traverse up in LINQ-XML?

Rahul Singh

Rahul Singh

9y
969
1
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)