-1

If I use XMLReader.Create, and pass it a stream, the XMLReader appears to read the entire stream even before I call any read methods, because the position property of the stream changes to match the length of the stream. Is XMLReader then storing the entire xml in memory? It would appear so as I can call XmlReader.Read and the stream position never changes. Is it possible for XmlReader to not consume the entire stream?

Jeremy
  • 44,950
  • 68
  • 206
  • 332
  • take a look at the following link perhaps you need to read your data in a While Loop http://www.java2s.com/Code/CSharp/XML/ReadingfromanXMLfile.htm || [MSDN / Stackoverflow posting](http://stackoverflow.com/questions/904129/how-to-use-xmlreader-class) – MethodMan Oct 17 '14 at 18:36

1 Answers1

2

XmlReader does not read the entire stream at once, it only reads blocks of (up to) 8192 bytes at a time from the stream (or more if Async is set to true) and stores them in an internal byte buffer. Obviously, if your stream has less bytes than that, it will read them all on the first Read() call. This is likely what you are experiencing.

John Rasch
  • 62,489
  • 19
  • 106
  • 139