You did it wrong. You need to parse XML as you read, without reading it in intermediate text file. Do you want to have double set of data in your memory, raw XML and XML parsed from a file? This is absurd, especially when your concern is the memory limitation.
Most economic and fast way of parsing XML offered by .NET FCL is the class
, which should operate directly on a file on disk or a stream, without using any intermediate text:
XmlReader Class (System.Xml)
Now, eventually the size of a file can grow beyond the limit of available system RAM. It's especially easy with x86 processes which are limited by 4G of address space, and really available memory will be considerably less. With WOW64 in a 64-bit system the situation is with a x86 (32-bit) process can be considerably better (you don't need the whole OS to reside in part of this memory), but principle limitation is still the same.
So, with this approach, you can develop the technique of parsing just the part of file, skipping nodes which are no longer needed. One benefit of
is that you only navigate through XML tree, but actually read and store in memory only what you want.
The alternative implementation of this idea can be achieved with another XML parsing approach. You can use the class
; this is the most adequate way similar to that of
, supporting LINQ to XML
programming. Please see:
LINQ to XML Overview
LINQ to XML