1 #!/usr/bin/env python 2 3 import libxml2dom, xml.dom, xml.dom.minidom 4 5 document = libxml2dom.createDocument(None, "doc", None) 6 top = document.xpath("*")[0] 7 elem1 = document.createElementNS("DAV:", "myns:href") 8 elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:myns", "DAV:") 9 elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:otherns", "urn") 10 document.replaceChild(elem1, top) 11 print document.toString() 12 13 document2 = xml.dom.minidom.Document() 14 elem1 = document2.createElementNS("DAV:", "myns:href") 15 elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:myns", "DAV:") 16 elem1.setAttributeNS(xml.dom.XMLNS_NAMESPACE, "xmlns:otherns", "urn") 17 document2.appendChild(elem1) 18 print document2.toxml() 19 20 # vim: tabstop=4 expandtab shiftwidth=4