开发者

pugixml "extend" element to add value

开发者 https://www.devze.com 2023-02-20 14:55 出处:网络
I trying to set the value of an 开发者_开发技巧element, regulary when the element looks like this <element></element> I just do this :

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消