views:

589

answers:

2

I want to read a large xml file (100+M). Due to its size, I do not want to load it in memory using XElement. I am using linq-xml queries to parse and read it.

What's the best way to do it? Any example on combination of XPath or XmlReader with linq-xml/XElement?

Please help. Thanks.

+3  A: 

Yes, you can combine XmlReader with the method XNode.ReadFrom, see the example in the documentation which uses C# to selectively process nodes found by the XmlReader as an XElement.

Martin Honnen
brilliant. i'm developing an app that will be processing multiple 200M XML files and XDocument was killing me. this has made a huge improvement. thanks.
Mike Jacobs
A: 

Just keep in mind that you will have to read the file sequentially and referring to siblings or descendants is going to be slow at best and impossible at worst. Otherwise @MartinHonnn has the key.

No Refunds No Returns