+ if (clean) {
+ clean_node(node);
+ }
+}
+
+Clone::Clone(const std::vector<Directive *> &subdirectives)
+ : subdirectives(subdirectives) {}
+
+Clone::Clone(std::initializer_list<Directive *> subdirectives)
+ : subdirectives(subdirectives) {}
+
+void Clone::process(xmlNode *node, bool clean) {
+ // We can't use xmlNewDocFragment, since xmlDOMWrapCloneNode only knows
+ // how to clone elements.
+ vector<xmlNode *> new_nodes;
+
+ for (auto it : subdirectives) {
+ xmlNode *new_node;
+ 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);
+ }
+ if (clean) {
+ clean_node(node);
+ }