libxml2dom quesiton
bruce
badouglas at gmail.com
Wed Sep 14 16:16:41 EDT 2011
Hi.
Test question. Trying to see how to insert a test node into an
existing dom tree. For the test, it has a TR/TD with a
td[@class="foo"] that has an associated TR..
Trying to figure out how out how to insert a "<DIV></DIV>" around the
tr/td in question...
Curious as to how to accomplish this.
Thoughts/pointers.
thanks
--------------------------
sample code/html chunk follows:
import libxml2dom
text is below
tt = libxml2dom.parseString(text, html=1)
t1path_=tt.xpath(t1path)
aa=tt.createElement("<div>")
print len(t1path_)
for a in t1path_:
tt.insertBefore(aa,None)
print a.nodeName
print a.toString()
sys.exit()
--------------------------------------------
s3==
<html>
<body>
<tr>
<td class="foo">
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td class="foo">
</td>
</tr>
</body>
</html>
trying to get::
<html>
<body>
<div>
<tr>
<td class="foo">
</td>
</tr>
</div>
<tr>
<td>
</td>
</tr>
<div>
<tr>
<td class="foo">
</td>
</tr>
</div>
</body>
</html>
More information about the Python-list
mailing list