paul@346 | 1 | #!/usr/bin/env python |
paul@346 | 2 | |
paul@346 | 3 | "Test text node insertion." |
paul@346 | 4 | |
paul@346 | 5 | import libxml2dom |
paul@346 | 6 | |
paul@346 | 7 | d = libxml2dom.createDocument(None, "test", None) |
paul@346 | 8 | |
paul@346 | 9 | t1 = d.createTextNode("Hello ") |
paul@346 | 10 | t2 = d.createTextNode("world") |
paul@346 | 11 | t3 = d.createTextNode("!") |
paul@346 | 12 | |
paul@346 | 13 | t1x = d.documentElement.appendChild(t1) |
paul@346 | 14 | t3x = d.documentElement.appendChild(t3) |
paul@346 | 15 | |
paul@346 | 16 | print d.toString() |
paul@346 | 17 | assert t2.parentNode is None |
paul@346 | 18 | assert t1.parentNode is not None |
paul@346 | 19 | assert t3.parentNode is not None |
paul@346 | 20 | |
paul@346 | 21 | t2x = d.documentElement.insertBefore(t2, t3) |
paul@346 | 22 | |
paul@346 | 23 | print d.toString() |
paul@346 | 24 | |
paul@346 | 25 | l = [n.data for n in t1.parentNode.childNodes] |
paul@346 | 26 | |
paul@346 | 27 | print l |
paul@346 | 28 | assert len(l) == 3 |
paul@346 | 29 | |
paul@346 | 30 | # vim: tabstop=4 expandtab shiftwidth=4 |