1.1 --- a/libxml2dom/macrolib/macrolib.py Sun Sep 14 22:55:59 2008 +0200
1.2 +++ b/libxml2dom/macrolib/macrolib.py Fri Sep 26 23:06:24 2008 +0200
1.3 @@ -429,13 +429,31 @@
1.4 return libxml2mod.xmlNewCDataBlock(Node_ownerDocument(node), value, len(value))
1.5
1.6 def Node_insertBefore(node, tmp, oldNode):
1.7 - return libxml2mod.xmlAddPrevSibling(oldNode, tmp)
1.8 +
1.9 + # Work around libxml2 tendency to merge text nodes and free nodes silently.
1.10 +
1.11 + if libxml2mod.type(tmp) == "text":
1.12 + placeholder = libxml2mod.xmlNewNode("tmp")
1.13 + placeholder = libxml2mod.xmlAddPrevSibling(oldNode, placeholder)
1.14 + libxml2mod.xmlReplaceNode(placeholder, tmp)
1.15 + return tmp
1.16 + else:
1.17 + return libxml2mod.xmlAddPrevSibling(oldNode, tmp)
1.18
1.19 def Node_replaceChild(node, tmp, oldNode):
1.20 return libxml2mod.xmlReplaceNode(oldNode, tmp)
1.21
1.22 def Node_appendChild(node, tmp):
1.23 - return libxml2mod.xmlAddChild(node, tmp)
1.24 +
1.25 + # Work around libxml2 tendency to merge text nodes and free nodes silently.
1.26 +
1.27 + if libxml2mod.type(tmp) == "text":
1.28 + placeholder = libxml2mod.xmlNewNode("tmp")
1.29 + placeholder = libxml2mod.xmlAddChild(node, placeholder)
1.30 + libxml2mod.xmlReplaceNode(placeholder, tmp)
1.31 + return tmp
1.32 + else:
1.33 + return libxml2mod.xmlAddChild(node, tmp)
1.34
1.35 def Node_removeChild(node, child):
1.36 libxml2mod.xmlUnlinkNode(child)