xml文档主要是:节点、属性、属性值

#include<iostream>
#include"pugixml/pugixml.hpp"
using namespace pugi;
using namespace std;
int main()
{
    xml_document doc;
    xml_parse_result result = doc.load_file("tree.xml");//parse解析,无错误则返回1
    //cout << result.description() << endl;//也可以把1描述出来,No error
    if (!result) return -1; //推荐直接写 if (!doc.load_file("tree.xml")) return -1;

    cout << doc.child("mesh").attribute("name").value() << endl; //节点mesh的属性name的值
    cout << doc.first_child().child_value() << endl;
    cout << doc.child("mesh").child("node").attribute("attr1").value() << endl; //节点mesh的节点node的属性attr1的值
    return 0;

    doc.print(cout); //展示文档内容
}

tree.xml

<mesh name="mesh_root">
    <node attr1="value1" attr2="value2" />
</mesh>

 

相关文章:

  • 2022-12-23
  • 2021-04-03
  • 2021-08-29
  • 2021-07-18
  • 2021-12-05
  • 2021-10-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案