1
Answer

Streamreader out of memory exception parsing XML document

Craig Davis

Craig Davis

11y
2.7k
1
I have a 80MB XML file that has no carriage returns.  I would like to find the count of an element within the document.  The following code:

StreamReader reader = File.OpenText(file.xml);

string
contents = reader.ReadToEnd();

MatchCollection matches1 = Regex.Matches(contents, "<element>");

count1 = matches1.Count;


produces an out of memory exception error for contents string . 

Any suggestions?

Answers (1)