libxml2dom quesiton

Discussion in 'Python' started by bruce, Sep 14, 2011.

  1. bruce

    bruce Guest

    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>
     
    bruce, Sep 14, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ankit

    problem with libxml2dom

    ankit, Dec 27, 2005, in forum: Python
    Replies:
    0
    Views:
    275
    ankit
    Dec 27, 2005
  2. ankit

    problems with libxml2dom

    ankit, Dec 27, 2005, in forum: Python
    Replies:
    1
    Views:
    540
    Paul Boddie
    Jan 4, 2006
  3. ankit

    libxml2dom problems

    ankit, Dec 27, 2005, in forum: Python
    Replies:
    2
    Views:
    630
    ankit
    Dec 28, 2005
  4. ankit
    Replies:
    4
    Views:
    3,347
    ankit
    Dec 28, 2005
  5. bruce

    python/libxml2dom questions

    bruce, Jul 2, 2006, in forum: Python
    Replies:
    3
    Views:
    555
    Stefan Behnel
    Jul 2, 2006
Loading...

Share This Page