I'm trying to read response from a web server using XmlTextReader. Here's a
code snippet.
WebResponse rs = this.WebRequest.GetResponse();
Stream stm = rs.GetResponseStream();
XmlTextReader reader = new XmlTextReader(stm);
reader.XmlResolver = null; // no DTD/schema, high perf
while (reader.Read()){
switch (reader.NodeType){
default:
Debug.WriteLine(string.Concat(
reader.NodeType.ToString(), ": ",
"<", reader.Name, ">",
reader.Value));
break;
}
}
and data on the web is like this:
<?xml version="1.0"
encoding="utf-8"?><cw><transaction>ad7191bc-0c36-4de1-9038-9537377228bd</tra
nsaction></cw>
Reading is fine, but problem occurs when it reaches at the end of stream.
After reading </cw>, XmlReader.read() throws exception:
System.Xml.XmlException: Root element not present
If I look in debugger, stm is ConnectStream and its EOF property is true,
but that's not a public property.
XmlReader.EOF is a public property, but it's false.
Is this normal behavior? Why can't reader.Read() returns false at the end of
stream?
I'm using VS.NET 2003; i.e., .NET Framework 1.1.
Thanks for any help or pointers in advance.
Thanks,
Koji Ishii