1 #!/usr/bin/env python 2 3 "Test of elements and attribute interfaces." 4 5 import libxml2dom 6 7 d = libxml2dom.parseString("<ddd:doc xmlns:ddd='http://ddd'/>") 8 e = d.xpath("*")[0] 9 assert e.parentNode == d 10 assert e.namespaceURI == "http://ddd" 11 assert e.nodeName == e.tagName == "ddd:doc" 12 assert e.localName == "doc" 13 e.setAttributeNS("http://xxx", "xxx:x", "y") 14 assert e.getAttributeNS("http://xxx", "x") == "y" 15 l = e.xpath("@*") 16 assert len(l) == 1 17 a = l[0] 18 assert a.parentNode == e 19 assert a.namespaceURI == "http://xxx" 20 assert a.nodeName == "xxx:x" 21 assert a.localName == "x" 22 assert a.nodeValue == a.value == "y" 23 a2 = d.createAttributeNS("http://aaa", "aaa:a") 24 a2.nodeValue = "b" 25 assert a2.namespaceURI == "http://aaa" 26 assert a2.nodeName == "aaa:a" 27 assert a2.localName == "a" 28 assert a2.nodeValue == a2.value == "b" 29 e.setAttributeNodeNS(a2) 30 l2 = e.xpath("@*") 31 assert len(l2) == 2 32 e.setAttributeNS("http://ccc", "ccc:c", "d") 33 assert e.getAttributeNS("http://ccc", "c") == "d" 34 l3 = e.xpath("@*") 35 assert len(l3) == 3 36 e.setAttribute("p", "q") 37 assert e.getAttribute("p") == "q" 38 l4 = e.xpath("@*") 39 assert len(l4) == 4 40 print d.toString() 41 42 # vim: tabstop=4 expandtab shiftwidth=4