libxml2dom quesiton

B

bruce

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top