1 #!/usr/bin/env python 2 3 import libxml2dom, xml.dom.minidom 4 5 def test(document, e): 6 e.setAttributeNS("xxx", "yyy", "zzz") 7 e.setAttributeNS("xxx", "yyy", "zzz") 8 e.setAttributeNS("xxx", "x:yyy", "zzz") 9 e.setAttributeNS("xxx", "x:yyy", "zzz") 10 e2 = document.createElementNS("DAV:", "d:abc") 11 e.appendChild(e2) 12 e2.setAttributeNS(None, "pqr", "xyz") 13 e2.setAttributeNS("DAV:", "qrs", "tuv") 14 e3 = document.createElementNS(None, "def") 15 e2.appendChild(e3) 16 e3.setAttributeNS("DAV:", "fgh", "ijk") 17 e3.setAttributeNS(None, "nop", "wxy") 18 19 document = libxml2dom.createDocument(None, "doc", None) 20 e = document.xpath("*")[0] 21 test(document, e) 22 print document.toString(prettyprint=1) 23 24 document = xml.dom.minidom.getDOMImplementation().createDocument(None, "doc", None) 25 e = document.documentElement 26 test(document, e) 27 print document.toprettyxml() 28 29 try: 30 from xml.dom.ext import PrettyPrint 31 PrettyPrint(document) 32 except ImportError: 33 print "PrettyPrint not tested." 34 35 try: 36 import pxdom 37 document = pxdom.getDOMImplementation("").createDocument(None, "doc", None) 38 e = document.documentElement 39 test(document, e) 40 out = pxdom.getDOMImplementation("").createDOMSerializer() 41 print out.writeToString(document) 42 except ImportError: 43 print "pxdom not tested." 44 45 # vim: tabstop=4 expandtab shiftwidth=4