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