1 #!/usr/bin/env python 2 3 """ 4 An import node implementation taken from libxml2dom.Node for use with libxml2macro. 5 """ 6 7 from libxml2dom.macrolib.macrolib import * 8 import xml.dom 9 10 def importNode(x2_self, x2_node, deep): 11 12 if x2_node.nodeType == xml.dom.Node.ELEMENT_NODE: 13 x2_imported_element = x2_self.ownerDocument.createElementNS(x2_node.namespaceURI, x2_node.tagName) 14 for x2_value in x2_node.attributes.values(): 15 x2_imported_element.setAttributeNS(x2_value.namespaceURI, x2_value.nodeName, x2_value.nodeValue) 16 17 if deep: 18 for child in x2_node.childNodes: 19 x2_imported_child = x2_self.importNode(child, deep) 20 if x2_imported_child: 21 x2_imported_element.appendChild(x2_imported_child) 22 23 return x2_imported_element 24 25 elif x2_node.nodeType == xml.dom.Node.TEXT_NODE: 26 return x2_self.ownerDocument.createTextNode(x2_node.nodeValue) 27 28 elif x2_node.nodeType == xml.dom.Node.ATTRIBUTE_NODE: 29 return x2_self.ownerDocument.createAttributeNS(x2_node.namespaceURI, x2_node.name) 30 31 elif x2_node.nodeType == xml.dom.Node.COMMENT_NODE: 32 return x2_self.ownerDocument.createComment(x2_node.data) 33 34 raise ValueError, x2_node.nodeType 35 36 # Special hack for the generated code. 37 38 Node_importNode = importNode 39 40 # vim: tabstop=4 expandtab shiftwidth=4