rapidxml - überschreibt vorherige xml_nodes
Ich habe gerade mit rapidxml angefangen. Ich erstelle eine XML-Datei zum Lesen. Arbeitete so schnell und einfach.
Dies ist, was ich manuell erstellt habe.
<?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>
Das konnte ich problemlos lesen. Ich wollte es dann in eine neue Datei schreiben. Das Problem ist jedoch, dass die vorherigen xml_nodes weiterhin überschrieben werden.
Zum Beispiel,
<?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>
Dies ist der Code, der diese XML-Datei erstellt,
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;
};
Meine Frage ist, wie ich verhindern kann, dass vorherige xml_nodes überschrieben werden. Ich habe viele Dinge versucht, aber jedes Mal werden die vorherigen xml_nodes überschrieben. Ich weiß, dass es einfach sein muss, oder mir fehlt das große Ganze.
Vielen Dank für Ihre Hilfe und Zeit!