【问题标题】:xml parsing in c++ using tinyxml使用 tinyxml 在 C++ 中解析 xml
【发布时间】:2011-09-25 18:57:57
【问题描述】:

我正在用 C++ 创建 xml 文件 我编写的代码就像在 C++ 中创建编写 xml 文件一样,如下所示

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");

但现在我只需要 XMl 文件中的数据而不是标签 伙计们请帮助我。

【问题讨论】:

    标签: c++ xml parsing tinyxml


    【解决方案1】:

    我建议阅读TinyXml documentation,更具体地说是TiXmlElement documentation

    对于您的特殊情况,我会说它看起来像这样:

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

    虽然我不是 TinyXml 方面的专家。

    仅供参考:

    在问这些琐碎的问题之前,请先搜索 GoogleStackOverflow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多