| re: VC++ .NET 2003: XmlTextReader Class Generates A Runtime Exception
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" <SHC@discussions.microsoft.com> wrote in message
news:1435ED44-0920-4EE5-825B-2DE25C99D4B0@microsoft.com...[color=blue]
> Hi all,
> I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP[/color]
Pro[color=blue]
> PC. On the c:\ screen, I got the following: Microsoft Development[/color]
Environment[color=blue]
> An unhandled exception of type 'System.Xml.XmlException'[/color]
occured[color=blue]
> 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[/color]
an[color=blue]
> 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[/color]
intended[color=blue]
> to correct the problem that is described in this article. Only apply it to
> systems that are experiencing this specific problem. This hotfix may[/color]
receive[color=blue]
> 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[/color]
(SP1)[color=blue]
> 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[/color]
not[color=blue]
> 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[/color]
attributes.[color=blue]
> 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[/color] |