3
std::string src = "<xml><node1>aaa</node1><node2>bbb</node2><node1>ccc</node1></xml>";
std::string src2 = "<nodex>xxx</nodex>";
我想用RapidXml 到节点追加在SRC2树里面的src我这样做:如何使用RapidXml for C++使用字符串在xml_document中插入新节点?
xml_document<> xmldoc;
xml_document<> xmlseg;
std::vector<char> s(src.begin(), src.end());
std::vector<char> x(src2.begin(), src2.end());
xmldoc.parse<0>(&s[0]);
xmlseg.parse<0>(&x[0]);
xml_node<>* a = xmlseg.first_node(); /* Node to append */
xmldoc.first_node("xml")->append_node(a); /* Appending node a to the tree in src */
好,伟大它编译,但在运行时,我得到了这个可怕的错误:
void rapidxml::xml_node::append_node(rapidxml::xml_node*) [with Ch = char]: Assertion `child && !child->parent() && child->type() != node_document' failed. Aborted
我不知道该怎么办。 问题很简单我需要将一个节点附加到树(xml),但我有字符串。
我想这是因为我想插入一个树的节点到另一个树...只有节点分配一个给定的树可以被添加到该树......这吮吸......
有没有办法以一种简单的方式来做我所需要的?
谢谢。
谢谢你的答案,但工作是肯定的。我需要解析两个字符串才能获得两个节点。我不能错过这两个要求中的任何一个。分配节点使他们成为我想要追加的子节点,并且该示例有效,但这不是我的情况。对不起。无论如何,感谢您的帮助:) – Andry 2011-01-13 00:37:44