Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6184241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:30:11+00:00 2026-05-24T01:30:11+00:00

I wrote an application in C++ which generates an XML file out of class

  • 0

I wrote an application in C++ which generates an XML file out of class members. Now I want to read the generated file again and save all attributes and values back to the C++ classes.

My XML writer (writes with success):

void TDescription::WriteXml( XmlWriter^ writer )
{
    writer->WriteStartElement( "Description" );
    writer->WriteAttributeString( "Version", m_sVersion );
    writer->WriteAttributeString( "Author", m_sAuthor );
    writer->WriteString( m_sDescription );
    writer->WriteEndElement();
}

My XML reader (causes an exception):

void TDescription::ReadXml( XmlReader^ reader )
{
    reader->ReadStartElement( "Description" );
    m_sVersion = reader->GetAttribute( "Version" );
    m_sAuthor = reader->GetAttribute( "Author" );
    m_sDescription = reader->ReadString();
    reader->ReadEndElement();
}

My generated XML file:

<?xml version="1.0" encoding="utf-8"?>
<root Name="database" Purpose="try" Project="test">
     <!--Test Database-->
     <Description Version="1.1B" Author="it">primary</Description>
</root>

Here is the exception caused by the reader:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

Additional information: There is an error in XML document (2, 2).

What’s the problem with the code? I think that the XmlReader methods were not used the right way!?

Due to answer 1, I have changed the code:

reader->ReadStartElement( "root" );
reader->ReadStartElement( "Description" );
m_sVersion = reader->GetAttribute( "Version" );
m_sAuthor = reader->GetAttribute( "Author" );
m_sDescription = reader->ReadString();
reader->ReadEndElement();
reader->ReadEndElement();

Now, I don’t get an exception and m_sDescription gets the right value but m_sVersion and m_sAuthor are still empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:30:12+00:00Added an answer on May 24, 2026 at 1:30 am

    You have to call ReadStartElement for “root” before that.

    reader->ReadStartElement( "root" );     
    reader->ReadStartElement( "Description" );
    

    Edit: Read attribute

    reader->ReadToFollowing( "Description" );
    reader->MoveToFirstAttribute();
    String ^ m_sVersion = reader->Value;     
    reader->MoveToNextAttribute();
    String ^ m_sAuthor = reader->Value;           
    String ^ m_sDescription = reader->ReadString();     
    reader->ReadEndElement();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an application which generates an XML file using XmlReader and XmlWriter (with
I wrote an application which allows people to contribute plugins to extend the functionality.
I wrote an application recently, which relies on OpenID for authentication. A lot of
I wrote a simple WinAPI application in C++ which embeds the Abode Flash ActiveX
I have developed an application which can create Xml files from Xml schema with
I want to create an application in android in which the user selects a
I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I have a small application which I created using jeweler. The jeweler generates a
I've coded an application that generates XML files for use with a mobile phone
I wrote an application in the Eclipse, which was successfully compiled and run. After

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.