1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/libxml2dom/macrolib/importnode.py Sun Jan 16 01:16:41 2005 +0000
1.3 @@ -0,0 +1,40 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +An import node implementation taken from libxml2dom.Node for use with libxml2macro.
1.8 +"""
1.9 +
1.10 +from libxml2dom.macrolib.macrolib import *
1.11 +import xml.dom
1.12 +
1.13 +def importNode(x2_self, x2_node, deep):
1.14 +
1.15 + if x2_node.nodeType == xml.dom.Node.ELEMENT_NODE:
1.16 + x2_imported_element = x2_self.ownerDocument.createElementNS(x2_node.namespaceURI, x2_node.tagName)
1.17 + for x2_value in x2_node.attributes.values():
1.18 + x2_imported_element.setAttributeNS(x2_value.namespaceURI, x2_value.nodeName, x2_value.nodeValue)
1.19 +
1.20 + if deep:
1.21 + for child in x2_node.childNodes:
1.22 + x2_imported_child = x2_self.importNode(child, deep)
1.23 + if x2_imported_child:
1.24 + x2_imported_element.appendChild(x2_imported_child)
1.25 +
1.26 + return x2_imported_element
1.27 +
1.28 + elif x2_node.nodeType == xml.dom.Node.TEXT_NODE:
1.29 + return x2_self.ownerDocument.createTextNode(x2_node.nodeValue)
1.30 +
1.31 + elif x2_node.nodeType == xml.dom.Node.ATTRIBUTE_NODE:
1.32 + return x2_self.ownerDocument.createAttributeNS(x2_node.namespaceURI, x2_node.name)
1.33 +
1.34 + elif x2_node.nodeType == xml.dom.Node.COMMENT_NODE:
1.35 + return x2_self.ownerDocument.createComment(x2_node.data)
1.36 +
1.37 + raise ValueError, x2_node.nodeType
1.38 +
1.39 +# Special hack for the generated code.
1.40 +
1.41 +Node_importNode = importNode
1.42 +
1.43 +# vim: tabstop=4 expandtab shiftwidth=4