473,387 Members | 3,821 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,387 software developers and data experts.

XmlTextReader; XmlException

edi
Hi,

I have MS .Net Framework v1.1.4322.
I have this XML file:

<?xml version="1.0" ?> <!--here there are two spaces at the
beginning-->
<aaa>
<a id="1">
<Dept>Finance</Dept>
</a>
<a id="2">
<Dept>Marketing</Dept>
</a>
</aaa>

This file opens correctly with Internet Explorer.
When I try to read from it with XmlTextReader the code throws
XmlException.
Here is the code:
XmlTextReader reader=new
XmlTextReader("EmpRec.xml");
try
{
reader.Read();
reader.Read(); //!!!EXCEPTION
}
catch (XmlException e){
Console.WriteLine(e.ToString());
}
Console result:
System.Xml.XmlException: The XML declaration is unexpected. Line 1,
position 5.
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
at MyProject.MyForm.ReadX() ...
It works correctly when I remove two spaces at the beginning of the XML
file.
What can I do to remove this problem easily? And why first Read
(reader.Read();) passes?

Thanks

Nov 12 '05 #1
1 1829


edi wrote:

I have MS .Net Framework v1.1.4322.
I have this XML file:

<?xml version="1.0" ?> <!--here there are two spaces at the

^^^
The XML declaration has to be at the start of the XML document, it could
only be preceded by a byte order mark (BOM) necessary for instance for
UTF-16 encoded documents.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

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

Similar topics

1
by: Koji Ishii | last post by:
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...
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...
3
by: Michael | 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...
2
by: SHC | last post by:
Hi all, I read the Microsoft KB Q815658 "How to read the XML data from a file using Visual C++ .NET" and tried to follow the steps of executing its source code in my VC++ .NET 2003 under Console...
1
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
2
by: pesso | last post by:
I have the following code that's taken and modified from a got_dot_net example. I'm trying to decrypt an Xml file that's been encrypted. I can dump the decrypted stream to the console, but if I...
2
by: Rob Richardson | last post by:
Greetings! I am introducing myself to VB .Net by rewriting a stock market simulation program that I developed in VB6. The original program uses MSHTML, the DOMDocument class and the various...
1
by: BLUE | last post by:
In a property i do this: .... catch(XmlException e) { throw new XmlException("Error processing configuration file!",e); } Then I catch it in another class: catch(XmlException e) {
3
by: =?Utf-8?B?RWQgS3JhbWVy?= | last post by:
I thought this might be useful for someone... I was doing a little work earlier using an Xmldocument class to create & maintain a minor store of data in Xml format. I'd gotten the whole thing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...

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.