xml字符串使用

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_42237844/article/details/100896746

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;
    }

猜你喜欢

转载自blog.csdn.net/qq_42237844/article/details/100896746