用tinyxml2读写xml文件_C++实现

下载源代码

开源代码github地址: https://github.com/leethomason/tinyxml2

添加工程文件

将源代码目录中 tinyxml2.htinyxml2.cpp 文件拷贝到工程目录下,并加入到工程中。

添加头文件和命名空间

#include "tinyxml2/tinyxml2.h"
using namespace tinyxml2;

写入代码片段: attribute name可以用任意名字,并且同一级nodes可以用相同的element name

tinyxml2::XMLElement* cityElement = doc.NewElement( "City" );
cityElement->SetAttribute( "name_xyz", "ChangSha" ); // 设置元素属性
root->InsertEndChild( cityElement );

tinyxml2::XMLElement
* cityElement = doc.NewElement( "City" ); cityElement->SetAttribute( "name_xyz", "ChangSha" ); // 设置元素属性 root->InsertEndChild( cityElement );
原文地址:https://www.cnblogs.com/xbit/p/9046094.html