微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在tinyxml2中附加两个xml文件

如何解决如何在tinyxml2中附加两个xml文件

我有两个 XML 文件

first.xml

<?xml version="1.0" encoding="UTF-8"?>
<Average>
    <source unit="FP">
        <brand name="Add" abbreviation="addition" value="0">            
            <mask value="1" name="Integer"/>
            <description></description>
        </brand>
        <brand name="Sub" abbreviation="substraction" value="1">            
            <mask value="1" name="Integer"/>
            <description></description>
        </brand>
    </source>
</Average>

second.xml

<source unit="PE">
    <brand name="Mul" abbreviation="multiplication" value="0">            
            <mask value="1" name="Integer"/>
            <description></description>
    </brand>
    <brand name="Div" abbreviation="division" value="0">            
            <mask value="1" name="Integer"/>
            <description></description>
    </brand>
</source>

我想将 second.xml 文件内容附加到 first.xml 文件

预期输出

<?xml version="1.0" encoding="UTF-8"?>
<Average>
    <source unit="FP">
        <brand name="Add" abbreviation="addition" value="0">            
            <mask value="1" name="Integer"/>
            <description></description>
        </brand>
        <brand name="Sub" abbreviation="substraction" value="1">            
            <mask value="1" name="Integer"/>
            <description></description>
        </brand>
    </source>
    <source unit="PE">
    <brand name="Mul" abbreviation="multiplication" value="0">            
            <mask value="1" name="Integer"/>
            <description></description>
    </brand>
    <brand name="Div" abbreviation="division" value="0">            
            <mask value="1" name="Integer"/>
            <description></description>
    </brand>
</source>
</Average>

这是我正在尝试的:

#include<iostream>
#include<string>
#include "tinyxml2.h"

void doAccess(const std::string& first,const std::string& second)
{
    std::string outFile = "output.xml";
    tinyxml2::XMLDocument doc;

    if (tinyxml2::XML_SUCCESS == doc.LoadFile(first.c_str()))
    {
        std::cout << "File is Present\n";
        doc.SaveFile(outFile.c_str());
    }

    if (tinyxml2::XML_SUCCESS == doc.LoadFile(second.c_str()))
    {
        std::cout << "File is Present\n";
        doc.SaveFile(outFile.c_str());
    }
}

int main()
{
    std::string first = "first.xml";
    std::string second = "second.xml";

    doAccess(first,second);

    return 0;
}

任何帮助将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。