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