How to create a xml node using rapidxml

332 Views Asked by At

Hi I want to create the following xml file in C++ using rapidxml on Linux. How to add an element which is of type name.

    <wrapit>
       <mainNode>
          <name>something1</name>
       </mainNode>
    </wrapit>

what my code generates looks like following which I don't want.

    <wrapit>
       <mainNode>
          <name something1=""/>
       </mainNode>
    </wrapit>

I could not find much information for this. Few on wordpress but the xml formats are different.

Code snippet

xml_node<>* root = doc.allocate_node(node_element, "mainNode");
doc.append_node(root);
xml_node<>* child = doc.allocate_node(node_element,"name");
child->append_attribute(doc.allocate_attribute("something1"));
root->append_node(child);
1

There are 1 best solutions below

0
punith On

ugg....

xml_node<>* child = doc.allocate_node(node_element,"name","something1"); 

does it.