开发者

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 n开发者_Go百科eed only the data in the XMl file not the tags guys plz help me.


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:

  • StackOverflow search function
  • Some - Answers - You - should have - considered ....

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜