473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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){
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

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

Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
2
by: Mitch | last post by:
I have some simple HTML I'm trying to read with the XMLTextReader. As in the MSDS examples, I set up a loop to read each XML node: while (reader.Read()) { switch (reader.NodeType) { case...
2
by: Mark | last post by:
Hi there, I have two xml files, one is a master file and the other is just a fragment of xml. Master xml file uses 'DOCTYPE' to define the other file as an entity. Then, the master uses entity...
1
by: Mark | last post by:
Hi there, I have two xml files, one is a master file and the other is just a fragment of xml. Master xml file uses 'DOCTYPE' to define the other file as an entity. Then, the master uses entity...
1
by: Michael Hodges | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;815658 The page above solved all of my problems with one exception. When the file has strange data in it, possibly Japanese, I get the...
3
by: Testguy | last post by:
Hi, I have been reading various messages in this group, and could not find an answer regarding what I am trying to do. At least, I could not find an easy answer. I am trying to figure out how...
0
by: delphiconsultingguy | last post by:
Hi all, Spent WAAAYYY too much time trying to figure this out because there's not many good examples out there, so in the interest of sparing y'all from suff'rin same, I've pasted it into...
3
by: Dan Aldean | last post by:
Hi, I create this XML document: <?xml version="1.0"?> <Bookstore> <Book Genre="Novel" Style="hardcover"> <author> <first-name>Margaret</first-name> <last-name>Atwood</last-name> </author>
2
by: princymg | last post by:
Am trying to read an xml file using vb.net but i'm getting following error. Select XML file Exception: {0}System.Xml.XmlException: This is an unexpected token. The expected token is 'QUOTE'....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.