ammu
ammu

Reputation: 1

xml parsing in c++ using tinyxml

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.

Upvotes: 0

Views: 4191

Answers (1)

Gui13
Gui13

Reputation: 13561

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.

Upvotes: 3

Related Questions