From d8b19f8693d9521d2ccb6ef3c036d2cacc83a9ab Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Wed, 21 Sep 2011 22:56:40 +0200 Subject: [PATCH] Implement cloning for C++0x. --- c++0x/xml-template.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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) -- 2.39.2