Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / April 2005

Tip: Looking for answers? Try searching our database.

VC++ .NET 2003: XmlTextReader Errors C2144 & C1004

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SHC - 23 Apr 2005 19:27 GMT
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:
c:\Documents and Settings\Scott H. Chang\My Documents\Visual Studio
Projects\Q815658XMLRead\Q815658XMLRead.cpp(13): error C2144: syntax error :
'int' should be preceded by ';'
c:\Documents and Settings\Scott H. Chang\My Documents\Visual Studio
Projects\Q815658XMLRead\Q815658XMLRead.cpp(13): fatal error C1004: unexpected
end of file found
Please help and tell me where I made mistakes and how to correct these 2
errors.
Thanks in advance,
SHC
/////////---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();
}
Martin Honnen - 24 Apr 2005 13:38 GMT
>  I
> got the following 2 errors:
[quoted text clipped - 6 lines]
> Please help and tell me where I made mistakes and how to correct these 2
> errors.

> using namespace System;
> using namespace System::Xml
                            ^^^
There the semicolon is missing, you need
  using namespace System::Xml;
according to the error message.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

SHC - 24 Apr 2005 19:39 GMT
Hi Martin, Thanks for your response.
I corrected the error and did the "Build" again. 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 am new in VC++ .NET 2003 and XML programmming in VC++ .NET. I just have my
VC++ .NET 2003 installed and this "Q815658XMLRead" is my first XML
programming project.  I need to tell you the following 2 things:
1) When I read the Microsoft Q815658:How to read the XML data from a file by
using Viusual C++ .NET, I saw the step #6: Add a reference to System.xml.dll
in the project and the additional information is in the article of the
Microsoft Knowledge Base: 310674 - How To Add reference to a managedVisual
C++ project. I read it, but I did not understand it and I did not do any
thing about the "reference" in my project.
2)In the original code lisiting, void _tmain(void) was used in my project. I
changed it to int _tmain(int argc, char* argv[]) - this is based on my
guessing!!!

Did 1) and 2) cause the problem in my project?  Please hehp and advise me
how I can correct the problem and make the project working for me.

Many Thanks,  
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.