473,569 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.WriteLi ne(e.ToString() );
}
Console result:
System.Xml.XmlE xception: The XML declaration is unexpected. Line 1,
position 5.
at System.Xml.XmlT extReader.Parse Tag()
at System.Xml.XmlT extReader.Parse Root()
at System.Xml.XmlT extReader.Read( )
at MyProject.MyFor m.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 1837


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
1914
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 reader = new XmlTextReader(stm); reader.XmlResolver = null; // no DTD/schema, high perf while (reader.Read()){ switch (reader.NodeType){ default:
2
5579
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 XmlNodeType.Element: Console.WriteLine("<{0}>", reader.Name); break;
3
2887
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 following error: System.Xml.XmlException: '☼', hexadecimal value 0x0F, is an invalid character. Line 8, position 18. at...
2
2768
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 Application (.NET). I lauched a project 'Q815658XMLRead' (see the attached .cpp file below) and did the "Build" and I got the following 2 errors:...
1
2244
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 'System.Xml.XmlException' occured in system.xml.dll Addtional Information: System error |Break| |Continue| I clicked on the |Continue| and I got...
2
4076
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 try to load that into XmlTextReader, it throws XmlException. I'd appreciate your help. //create file stream to read encrypted file back...
2
1108
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 IHTML types to parse the contents of a web page that contains the market information for the stocks in the simulated portfolio. While it seems to be...
1
2150
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
3521
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 up and going and I decided to start testing 'disaster' scenarios. For example, you start up but your file has been deleted, or you try to save...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.