3

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?

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

That's correct; as per pugixml.googlecode.com/svn/tags/latest/docs/manual/… text inside the elements has its own node; <element/> has no child nodes (<element></element> also has none; <element>x</element> has a PCDATA child), so you need to explicitly append the node with the correct type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.