Is there an easy way with LINQ to flatten an XML file?
I can see a number of ways with XSLT but wondered what the best option with LINQ would be?
I cant put the xml structure up exactly as stackoverflow seems to filter chevron chars. But its something like this
nodeA
–nodeA1
–nodeA2
NodeB
I want to end up with
nodeA
nodeA1
nodeA2
NodeB
OK; it depends on the output you want – with XElement you’d need to do a bit of work to remove all the descendent nodes etc. However, it is actually quite simple with XmlDocument:
Outputs:
[was] Care to define ‘flatten’ in this context? i.e. ‘before’ and ‘after’? XDocument has Descendants() and DescendantNodes() which might do the job…