[reportlab-users] query! urgent

Aaron Watters reportlab-users@reportlab.com
Thu, 02 Jan 2003 11:32:31 -0500


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


Shaktinath Pandey wrote:

>I am using pyRXP parser in python,which parses the xml file and puts it
>in the form of Tuple Tree.
>
>for e.g 
> The xml file is like 
>
><PRODUCT>
>    <G1>
>        <P2></P2>
>        <G3>
>            <P3></P3>
>            <P4></P4>
>            <G5>
>                <G6></G6>
>                <G7></G7>
>            </G5>
>        </G3>
>        <G4></G4>
>    </G1>
>    <G2></G2>
>    <P1></P1>
></PRODUCT>
>
>The pyRXP parser will parse and put in the following format
>
>('PRODUCT', None, ['\t\n\t', ('G1', None, ['\n\t\t', ('P2', None, [],
>None), '\n\t\t', ('G3', None, ['\n\t\t\t', ('P3', None,
>[], None), '\n\t\t\t', ('P4', None, [], None), '\n\t\t\t', ('G5', None,
>['\n\t\t\t\t', ('G6', None, [], None), '\n\t\t\t\t', (
>'G7', None, [], None), '\n\t\t\t'], None), '\n\t\t'], None), '\n\t\t',
>('G4', None, [], None), '\n\t'], None), '\n\t', ('G2',
>None, [], None), '\n\t', ('P1', None, [], None), '\n'], None)
>
>
>Now I want to directly hit 'P2' from the above Tuple Tree
>i.e I don't want to traverse through the entire tree and reach to 'P2' i
>want 'P2' element directly.
>How can I achieve this what are the commands for that.
>
>regards!
>
>Shakti Nath Pandey
>Banking Bussiness Unit
>Infosys Technologies Ltd,
>Banglore
>_______________________________________________
>reportlab-users mailing list
>reportlab-users@reportlab.com
>http://two.pairlist.net/mailman/listinfo/reportlab-users
>