[reportlab-users] query! urgent

Dennis Allison reportlab-users@reportlab.com
Thu, 2 Jan 2003 09:47:07 -0800


"Shaktinath Pandey" <Shaktinath_Pandey@infosys.com> 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.

You could build a dictionary where the key is a tag and the value is
a list of tuples since, for example, <P2> is not necessarily uniquei,
but I think this is a bad idea.  I believe you should rethink what you
are trying to accomplish since your request is out of keeping with the
philosophy behind using an XML representation.  As Robin pointed out,
it's fairly easy to hide the traversal complexity behind a wrapper
that implements your semantic model.