rapidxml – 覆盖以前的xml_nodes
我刚开始使用rapidxml.我首先创建一个xml文件来读取.工作得这么快就很容易了.
这是我手动创作的. <?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 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? 谢谢你的帮助和时间!
我不确定这是否会有所帮助,但这在
the documentation中存在:
我可以在你的代码中看到你的char数组x,y,z似乎是在你的循环范围内创建的,因此不满足上面的要求. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |