473,395 Members | 2,798 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,395 software developers and data experts.

VC++ .NET 2003: XmlTextReader Class Generates A Runtime Exception

SHC
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 the following:
"c:\Documents and Settings\Scott H. Chang\My Documents\Visual Studio
Projects\Q815658XMLRead.........
unhandled Excetion: System.Xml.XmlException:
The XML declaration is unexpected.
Line 1, position 4
at System.Xml.XmlTextReader.ParseTag<>
at System.Xml.XmlTextReader.ParseRoot<>
at System.Xml.XmlTextReaderRead<>
at main (Int32argc, SByte ** argv) in
c:\documents and
settings\.....\.....\q815658xmlread\q815658xml.cpp :line 17
The Line 17 in my .cpp program is "while (read->Read())".
I saw
(1) The Microsoft KB Article ID: 818777
FIX: The XmlTextReader class generates a runtime exception when you read an
XML document
View products that this article applies to.
Article ID : 818777
Last Review : April 27, 2004
Revision : 1.0
On this page
SYMPTOMS
CAUSE
RESOLUTION
WORKAROUND
STATUS
REFERENCES
APPLIES TO

SYMPTOMS
When you use the XmlTextReader class to read an XML document, you may
receive the following runtime exception error message:
Value must be positive. Parameter name: startIndex
at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32
charCount)
at System.Xml.XmlTextReader.ParseXmlDecl()
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
Back to the top

CAUSE
This problem occurs if there is a delay when the XmlTextReader class reads
an XML document from a Stream object.
Back to the top

RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended
to correct the problem that is described in this article. Only apply it to
systems that are experiencing this specific problem. This hotfix may receive
additional testing. Therefore, if you are not severely affected by this
problem, Microsoft recommends that you wait for the next Microsoft .NET
Framework 1.1 service pack that contains this hotfix.
(2) Microsoft .NET Framework 1.1 Service Pack1 (File Name:
NDP11.1sd1-KB867460-x86.exe Version 1.0 that was published 8/30/2004) said
that the primary focus of Microsoft .NET Framework 1.1 Service Pack 1 (SP1)
is improved security.

I am completely lost in this matter. Please hehp and advise me
how I can correct the problem and make the project working for me.

Thanks in advance,
SHC

P. S. I itried to abort my "Build" process after 'Debug' and 'Break'. I
clicked on the
"Build" menu, I just saw 'Configuration Managert' only and I do not
know how
to abort this process now. Please advise on this matter also.

/////////---Q815658XMLread.cpp----////////////
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"
#include <tchar.h>

#using <mscorlib.dll>
#using <system.xml.dll>

using namespace System;
using namespace System::Xml;

int _tmain(int argc, char* argv[])
{
XmlTextReader* reader = new XmlTextReader ("books.xml");

while (reader->Read())
{
switch (reader->NodeType)
{
case XmlNodeType::Element: // The node is an element.
Console::Write("<{0}", reader->Name);

while (reader->MoveToNextAttribute()) // Read the attributes.
Console::Write(" {0}='{1}'", reader->Name, reader->Value);
Console::WriteLine(">");
break;
case XmlNodeType::Text: //Display the text in each element.
Console::WriteLine (reader->Value);
break;
case XmlNodeType::EndElement: //Display the end of the element.
Console::Write("</{0}", reader->Name);
Console::WriteLine(">");
break;
}
}
Console::ReadLine();
}


SHC
Nov 12 '05 #1
1 2222
Hi,

The said XmlException is thrown when the xml declaration (ie. <?xml ... ?>)
is not at the very beginning of the xml document. Move the xml declaration
at the beginning of the xml document (no preceding whitespace) and the
project should start working for you.

Ion

"SHC" <SH*@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
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 the following:
"c:\Documents and Settings\Scott H. Chang\My Documents\Visual Studio
Projects\Q815658XMLRead.........
unhandled Excetion: System.Xml.XmlException:
The XML declaration is unexpected.
Line 1, position 4
at System.Xml.XmlTextReader.ParseTag<>
at System.Xml.XmlTextReader.ParseRoot<>
at System.Xml.XmlTextReaderRead<>
at main (Int32argc, SByte ** argv) in
c:\documents and
settings\.....\.....\q815658xmlread\q815658xml.cpp :line 17
The Line 17 in my .cpp program is "while (read->Read())".
I saw
(1) The Microsoft KB Article ID: 818777
FIX: The XmlTextReader class generates a runtime exception when you read an XML document
View products that this article applies to.
Article ID : 818777
Last Review : April 27, 2004
Revision : 1.0
On this page
SYMPTOMS
CAUSE
RESOLUTION
WORKAROUND
STATUS
REFERENCES
APPLIES TO

SYMPTOMS
When you use the XmlTextReader class to read an XML document, you may
receive the following runtime exception error message:
Value must be positive. Parameter name: startIndex
at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32
charCount)
at System.Xml.XmlTextReader.ParseXmlDecl()
at System.Xml.XmlTextReader.ParseTag()
at System.Xml.XmlTextReader.ParseRoot()
at System.Xml.XmlTextReader.Read()
Back to the top

CAUSE
This problem occurs if there is a delay when the XmlTextReader class reads
an XML document from a Stream object.
Back to the top

RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to
systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this
problem, Microsoft recommends that you wait for the next Microsoft .NET
Framework 1.1 service pack that contains this hotfix.
(2) Microsoft .NET Framework 1.1 Service Pack1 (File Name:
NDP11.1sd1-KB867460-x86.exe Version 1.0 that was published 8/30/2004) said
that the primary focus of Microsoft .NET Framework 1.1 Service Pack 1 (SP1) is improved security.

I am completely lost in this matter. Please hehp and advise me
how I can correct the problem and make the project working for me.

Thanks in advance,
SHC

P. S. I itried to abort my "Build" process after 'Debug' and 'Break'. I
clicked on the
"Build" menu, I just saw 'Configuration Managert' only and I do not know how
to abort this process now. Please advise on this matter also.

/////////---Q815658XMLread.cpp----////////////
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"
#include <tchar.h>

#using <mscorlib.dll>
#using <system.xml.dll>

using namespace System;
using namespace System::Xml;

int _tmain(int argc, char* argv[])
{
XmlTextReader* reader = new XmlTextReader ("books.xml");

while (reader->Read())
{
switch (reader->NodeType)
{
case XmlNodeType::Element: // The node is an element.
Console::Write("<{0}", reader->Name);

while (reader->MoveToNextAttribute()) // Read the attributes. Console::Write(" {0}='{1}'", reader->Name, reader->Value);
Console::WriteLine(">");
break;
case XmlNodeType::Text: //Display the text in each element.
Console::WriteLine (reader->Value);
break;
case XmlNodeType::EndElement: //Display the end of the element.
Console::Write("</{0}", reader->Name);
Console::WriteLine(">");
break;
}
}
Console::ReadLine();
}


SHC

Nov 12 '05 #2

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

Similar topics

5
by: Venky | last post by:
We have a strange error here. We have an application that is built in VC++ 6.0 and uses a C library built using the same. Now, we have migrated to .Net and have used the same source code to be...
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: 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...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
9
by: Hasani \(remove nospam from address\) | last post by:
I was reading a ppt ( http://www.gotdotnet.com/team/pdc/4064/tls310.ppt ) and came aross this statement. "Users can leverage a destructor. The C++ compiler generates all the Dispose code...
6
by: Felix I. Wyss | last post by:
It appears that VC++2003 has a code generator bug related to template parameters that are a pointer-to-member type: If the actual template argument is a virtual method, VC generates code that...
16
by: John Gabriel | last post by:
The *back* and *forward* butttons do not work. Anyone noticed this? I know this is a beta edition but even for a beta edition, it's hard to believe Microsoft performed any real quality...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
6
by: Volodia | last post by:
Hi, I have a problem to find information how to add unmanaged dll build in VC++ 2005 to the asp.net web site What I have tried: 1. use DllImport("MyDll.dll") to declare function in...
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:
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
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.