Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13285 > unrolled thread

libxml2dom quesiton

Started bybruce <badouglas@gmail.com>
First post2011-09-14 13:16 -0700
Last post2011-09-14 13:16 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  libxml2dom quesiton bruce <badouglas@gmail.com> - 2011-09-14 13:16 -0700

#13285 — libxml2dom quesiton

Frombruce <badouglas@gmail.com>
Date2011-09-14 13:16 -0700
Subjectlibxml2dom quesiton
Message-ID<mailman.1129.1316031403.27778.python-list@python.org>
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>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web