From: sgunderson@bigfoot.com <> Date: Wed, 21 Sep 2011 20:56:40 +0000 (+0200) Subject: Implement cloning for C++0x. X-Git-Url: https://git.sesse.net/?p=xml-template;a=commitdiff_plain;h=d8b19f8693d9521d2ccb6ef3c036d2cacc83a9ab Implement cloning for C++0x. --- diff --git a/c++0x/xml-template.cpp b/c++0x/xml-template.cpp index a3156e7..7278236 100644 --- a/c++0x/xml-template.cpp +++ b/c++0x/xml-template.cpp @@ -16,6 +16,24 @@ Clone::Clone(const std::vector &subdirectives) : subdirectives(subdirectives) {} void Clone::process(xmlNode *node, bool clean) { + // We can't use xmlNewDocFragment, since xmlDOMWrapCloneNode only knows + // how to clone elements. + vector new_nodes; + + for (auto it : subdirectives) { + xmlDOMWrapCtxt ctx; + xmlNode *new_node; + int ret = xmlDOMWrapCloneNode(NULL, node->doc, node, &new_node, node->doc, NULL, 1, 0); + it->process(new_node, clean); + for (xmlNode *child = new_node->children; child != NULL; child = child->next) { + new_nodes.push_back(child); + } + } + + node->children = NULL; + for (auto child : new_nodes) { + xmlAddChild(node, child); + } } Substitute::Substitute(const unordered_map &substitution_map)