X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=c%2B%2B0x%2Fxml-template.cpp;h=7278236d911d6b50d4a1236a97fd6c8e5df8df7e;hb=d8b19f8693d9521d2ccb6ef3c036d2cacc83a9ab;hp=a3156e7b9ff888d644eb6424d23101ca8836e00b;hpb=c29512353e6e683b78ae50587b80e9a8db0797b1;p=xml-template 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)