我刚开始使用rapidxml。我第一次创建一个XML文件来读取。工作如此快速简单。rapidxml - 覆盖以前的xml_nodes
这是我手工制作的。
<?xml version="1.0" encoding="utf-8"?>
<GPS>
<Path>
<Point X="-3684.136" Y="3566.282" Z="285.2893" />
<Point X="-3681.816" Y="3540.431" Z="283.3658" />
<Point X="-3687.079" Y="3515.315" Z="282.6284" />
</Path>
</GPS>
我可以很容易地阅读,没有问题。然后我想把它写入一个新文件。 但问题是它会覆盖以前的xml_nodes。
例如,
<?xml version="1.0" encoding="UTF-8"?>
<GPS>
<Path>
<Point X="-3687.08" Y="3515.31" Z="282.628"/>
<Point X="-3687.08" Y="3515.31" Z="282.628"/>
<Point X="-3687.08" Y="3515.31" Z="282.628"/>
</Path>
</GPS>
这是创建一个XML文件中的代码,
int Write(pathStruct *toStore)
{
xml_document<> doc;
xml_node<>* decl = doc.allocate_node(node_declaration);
decl->append_attribute(doc.allocate_attribute("version", "1.0"));
decl->append_attribute(doc.allocate_attribute("encoding", "UTF-8"));
doc.append_node(decl);
xml_node<> *GPS = doc.allocate_node(node_element, "GPS");
doc.append_node(GPS);
cout << "Saving GrindPath " << endl;
xml_node<> *Path = doc.allocate_node(node_element, "Path");
GPS->append_node(Path);
for(int i = 0;i<3;i++) //Temp Static
{
xml_node<> *Point = doc.allocate_node(node_element, "Point");
Path->append_node(Point);
char x[10];
FloatToCharA(toStore->X[i], x);
Point->append_attribute(doc.allocate_attribute("X", x));
char y[10];
FloatToCharA(toStore->Y[i], y);
Point->append_attribute(doc.allocate_attribute("Y", y));
char z[10];
FloatToCharA(toStore->Z[i], z);
Point->append_attribute(doc.allocate_attribute("Z", z));
//GrindPath->append_node(Point);
//doc.first_node()->append_node(GrindPath);
//Point = GrindPath->next_sibling();
cout << "x:" << toStore->X[i] << " y:" << toStore->Y[i] << " z:" << toStore->Z[i] << endl;
}
cout << "Done! " << endl;
std::ofstream myfile;
myfile.open ("./toStore.xml");
myfile << doc;
return 0;
};
我的问题他怎么我从覆盖以前的xml_nodes停止吗? 我曾尝试过很多事情,但每次都会覆盖以前的xml_nodes。 我知道它一定很简单,或者我错过了大图。
谢谢你的帮助和时间!