2
Answers

How to Traverse up in LINQ-XML?

Rahul Singh

Rahul Singh

10y
972
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)
0
Vulpes

Vulpes

NA 98.3k 1.5m 12y
Quoted identifiers (i.e. identifiers surrrounded by double quotes) enable you to use names for identifiers which would otherwise be illegal such as reserved words or names which contain embedded spaces.

However, if you use them, then string literals must be enclosed in single quotes to distinguish them from quoted identifiers.