]> git.sesse.net Git - xml-template/blobdiff - c++11/xml-template.cpp
Implement prettyprinting in the PHP5 SWIG version.
[xml-template] / c++11 / xml-template.cpp
index 61d567fdacca1cf7d4a5ae1cd35951858bb316af..4f0c9fef6e903aa4a9772de64e176d612dd3c291 100644 (file)
@@ -14,12 +14,11 @@ void clean_node(xmlNode *node)
        }
        if (node->ns != NULL &&
            strcmp(reinterpret_cast<const char *>(node->ns->href), "http://template.sesse.net/") == 0) {
-               xmlNode *frag = xmlNewDocFragment(node->doc);
-               xmlReplaceNode(node, frag);
-               frag->children = node->children;
-               frag->last = node->last;
+               while (node->children != NULL) {
+                       xmlAddPrevSibling(node, node->children);
+               }
 
-               node->children = node->last = NULL;
+               xmlUnlinkNode(node);
                xmlFreeNode(node);
        }
 }
@@ -201,7 +200,7 @@ void Substitute::process(xmlNode *node, bool clean)
                                        xmlSetProp(child, attr_key, attr_value);
                                } else if ((!id.empty() && begins_with(it.first, "#" + id + "/"))) {
                                        const xmlChar *attr_key = reinterpret_cast<const xmlChar *>(
-                                               it.first.c_str() + tag.size() + 2);
+                                               it.first.c_str() + id.size() + 2);
                                        const xmlChar *attr_value = reinterpret_cast<const xmlChar *>(
                                                it.second->get_contents().c_str());
                                        xmlSetProp(child, attr_key, attr_value);