I have boiled the code down to this only and the output is shown at the bottom (it looks like I should have plenty of memory)
In this case, I get the out of memory exception at:
reader.MoveToContent();
I have also tried various other XmlReader methods and they all have generated the same exception.
The two XML files I need to read are very small. I could do this with some basic parsing but was hoping to take the opportunity to learn a bit more about XML.
Also, I googled this a little and I am still not sure how to do this:
Also look at the size of buffers allocated in the XML DLL.
Thanks again. Any clues or more info. is much appreciated.
Debug.Print("Avail memory before GC " + Debug.GC(false).ToString());
Debug.Print("Avail memory after GC " + Debug.GC(true).ToString());
string XmlData = @ "<?xml version=""1.0""?><note><body>This is the body.</body></note>";
Debug.Print(XmlData.ToString());
byte[] byteA = Encoding.UTF8.GetBytes(XmlData);
MemoryStream byteAstream = new MemoryStream(byteA);
XmlReader reader = XmlReader.Create(byteAstream);
reader.MoveToContent();
while (reader.Read())
{
// Do some work here on the data.
Debug.Print(reader.Name);
Thread.Sleep(1000);
}
Output:
Avail memory before GC 48168
Avail memory after GC 48192
<?xml version="1.0"?>This is the body.