473,237 Members | 1,092 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,237 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 1822


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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.