Re: [xml] Question about parent/child (python-libxml2)



Quoting Daniel Veillard <veillard redhat com>:
 I think it's all Stéphane Bidoul faults :-), he added support
for iterator at the Python level. 
 Since usually people have more trouble walking a tree in document
order than a simple linked list, his choice is probably what helps
Python users most, even if it's not obvious at a syntactic level
that the semantic recurses down the trees.

Well, from a Python point of view it feels a little bit unual.
As long as I know how to use it - an example code snippet(*)
would be of great help - I'm happy.  Thanks to you (and
Stephane) for providing software and help!

Cheers, WB

(*) The following code works for me:

#!/usr/bin/env python
import libxml2
dom = libxml2.parseDoc('''<?xml version="1.0"?>
<para>Then, shalt thou count to
<emphasis>three</emphasis>, no more, no less.</para>''')
nodes = dom.xpathEval("//para")
for n in nodes:
    if n.children:
        c = n.children
        while c != None:
            if c.name == "comment":
                continue
            print c.serialize()
            c = c.next



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]