I have two XML file.
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>
I want to append the content of second.xml file to first.xml file
Expected Output:
<?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>
Here is what I was trying:
#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;
}
Any help would be highly appreciated.
Aucun commentaire:
Enregistrer un commentaire