[reportlab-users] query! urgent

Robin Becker reportlab-users@reportlab.com
Thu, 2 Jan 2003 17:07:37 +0000


In article <3E14699F.8030702@reportlab.com>, Aaron Watters
<aaron@reportlab.com> writes
>Something like this?
>
>def findP2(parsedTuple):
>   import types
>   if type(parsedTuple) is types.TupleType:
>       (tagName, attributes, content) = parsedTuple[:3]
>       if tagName is "P2":
>           print "I found a P2!!!", attributes, content # if there is 
>only one P2 you can, eg, return content
>       else:
>           if content:
>               for thing in content:
>                   findP2(thing)
>
>-- Aaron Watters
as an alternative you could use the TagWrapper class from xmlutils.py in
the examples directory of the pyRXP sources.
########################
from xmlutils import TagWrapper, xml2doctree
t = TagWrapper(xml2doctree('''<PRODUCT><G1>
<P2>


this is P2

</P2>
<G3><P3></P3><P4></P4><G5><G6></G6><G7></G7></G5></G3><G4></G4></G1><G2>
</G2><P1></P1></PRODUCT>'''))

print str(t.G1.P2)
########################
this is P2
-- 
Robin Becker