0

i am creating xml file in c++ i wrote the code like creating writing the xml file in c++ as shown below

const char* assign =

    "<?xml version=\"1.0\"  standalone='no' >\n"
    "<office>"

    "<work>file created</work>"
    "</office>";

TiXmlDocument doc( "vls.xml" );
        doc.Parse( assign );

    if ( doc.Error() )
        {
            printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
            exit( 1 );
        }
        doc.SaveFile();


    bool loadOkay = doc.LoadFile();

    if ( !loadOkay )
    {
        printf( "Could not load test file 'vls.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
        exit( 1 );
    }
    else
        printf(" 'vls.xml' loaded successfully");

but now i need only the data in the XMl file not the tags guys plz help me.

1 Answer 1

3

I'd suggest reading the TinyXml documentation, more specifically the TiXmlElement documentation.

For your special case, I'd say it looks like that:

TiXmlElement * office = doc.FirstChildElement( "office" );
if( office )
{
   TiXmlElement *work = office.FirstChildElement( "work" );
   if( work )
   {
       printf("Work text: %s\n", work.GetText());
   }
}

Although I'm not an expert with TinyXml.

FYI:

Please, search Google and StackOverflow before asking such trivial questions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.