+ReplaceInclude::ReplaceInclude(xmlNodePtr included_node)
+ : included_node(included_node),
+ included_doc(NULL) {}
+
+ReplaceInclude::ReplaceInclude(xmlDocPtr included_doc)
+ : included_node(xmlDocGetRootElement(included_doc)),
+ included_doc(included_doc) {}
+
+ReplaceInclude::~ReplaceInclude()
+{
+ if (included_doc != NULL) {
+ xmlFreeDoc(included_doc);
+ } else {
+ xmlFreeNode(included_node);
+ }
+}
+
+void ReplaceInclude::process(xmlNode *node, bool clean) {
+ xmlFreeNodeList(node->children);
+ node->content = NULL;
+ node->children = node->last = NULL;
+
+ xmlNode *new_node;
+ xmlDOMWrapCloneNode(NULL, NULL, included_node, &new_node, node->doc, node, 1, 0);
+ xmlAddChild(node, new_node);
+
+ if (clean) {
+ Substitute dummy_subs {};
+ dummy_subs.process(new_node, clean);
+ clean_node(node);
+ }
+}
+