1、pugixml 读属性值,读xml文档

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>
原文地址:https://www.cnblogs.com/xixixing/p/12123142.html