"Doubt is uncomfortable, certainty is ridiculous." - Voiltaire

Better way to cleanly handle nested XML with LINQ

Better way to cleanly handle nested XML with LINQ
StackOverflow.com

I’m working with XML that was designed by somebody who got paid by the level of nesting. The different xml files always looks something like this:

<Car>
   <Color>
       <Paint>
          <AnotherUselessTag>
               <SomeSemanticBs>
                   <TheImportantData>

With LINQ its easy to get what I want: ( not exactly, but you get the point )

from x in car.Descendants("x")
from y in x.Descendants("y")
from z in y.Descendants("z")
select z.WhatIWant();

I’m asking if there is a better way to do this? Some way of navigating the DOM with Linq?


 
 
 

Leave a Reply