开发者

xml parsing in c++ using tinyxml

开发者 https://www.devze.com 2023-03-16 21:27 出处:网络
i am creating xml file in c++ i wrote the code like creating writing the xml file in c++ as shown below

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

精彩评论

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

关注公众号