版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1、新建根节点
tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* root = doc.NewElement("Config");
root->SetAttribute("Name", "PlotSymbol");
root->SetAttribute("Type", "GsPlotLinePictureSymbol");
2、将字符串转为xml
std::string str;
tinyxml2::XMLDocument doc2;
doc2.Parse(str.c_str());
3、将一段xml插入到另一段xml的某个字段下
tinyxml2::XMLElement *nodeSymbol = (tinyxml2::XMLElement *)(doc2.RootElement()->DeepClone(&doc));
nodeSymbol->SetAttribute("Name", "Symbol");
root->InsertEndChild(nodeSymbol);
4、将xml保存到文件
tinyxml2::XMLError bSuccess = doc.SaveFile(strSave.c_str());
if (bSuccess == tinyxml2::XML_SUCCESS)
{
return true;
}