469,628 Members | 1,033 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

Read HttpWebRespponse by XmlTextReader throws XmlException: Root element not present

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){
reader.NodeType.ToString(), ": ",
"<", reader.Name, ">",
and data on the web is like this:
<?xml version="1.0"

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

I'm using VS.NET 2003; i.e., .NET Framework 1.1.

Thanks for any help or pointers in advance.
Koji Ishii

Nov 11 '05 #1
1 1787
Never mind...my mistake. Sorry for the noise.

Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andy Neilson | last post: by
1 post views Thread by Mark | last post: by
3 posts views Thread by Dan Aldean | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.