Search code examples
c++xmlpugixml

pugixml "extend" element to add value


I trying to set the value of an element, regulary when the element looks like this <element></element> I just do this :

pugi::xml_node node = xmlBase.child("element");
pugi::xml_node nodechild = node.first_child();
nodechild.set_value(this->elementValue);

But, when I have an element looking like this:

<element />

this wont work.. i tried using this before the "set_value" row

if(nodechild == NULL)
{
    nodechild = node.append_child();
}

but this will create a new element within that element, and I dont want to do this,

Perhaps my fist approach is even wrong? how do you properly set the value of the element?


Solution

  • Seems like the Solution is to do this:

    nodechild = node.append_child(pugi::node_pcdata);
    

    this will create a child thats only plain text within the element