2

I am using RapidXML to modify an existing XML doc. This is my code:

    file<> xmlFile( launchFullPath.c_str() );
    xml_document<> doc;
    doc.parse<0>(xmlFile.data());

    // create a node called basedir
    xml_node<> *basedir = doc.allocate_node(node_element, "basedir");

    // append basedir to the launch
    xml_node<> *node = doc.first_node("launch");
    node->append_node(basedir);

    // append attribute to basedir
    xml_attribute<> *attr = doc.allocate_attribute("path", SUMOfullDirectory.c_str());
    basedir->append_attribute(attr);

Eventually, the content of the XML will be:

<launch>
    <copy file="hello.net.xml"/>
    <copy file="hello.rou.xml"/>
    <copy file="hello.loopDetector.xml"/>
    <copy file="hello.obstacles.xml"/>
    <copy file="hello.sumo.cfg" type="config"/>
    <basedir path="/home/mani/Desktop/VENTOS/sumo/Incident_Detection"/>
    <seed value="0"/>
</launch>

At the end, I want to convert the content of the XML doc into string. As you can see (from the debug mode in eclipse IDE) the content of the XML file is not properly stored into st variable. I used the RapidXML::print method as well, and the result is the same. What can be wrong here?

enter image description here

ManiAm
  • 1,759
  • 5
  • 24
  • 43
  • 1
    Be aware that Rapidxml is an "in-situ" parser, so I think it is working directing on the `file` buffer in your example. (Is your `file` class boost or something else?) Once you close the file your `doc` will be garbage. Do you have a complete example to replicate the problem? – Roddy Jun 02 '14 at 19:46

0 Answers0