[XML-SIG] automatically building Python data structures from DOM trees?

Uche Ogbuji Uche.Ogbuji at fourthought.com
Fri Dec 2 18:52:35 CET 2005


On Fri, 2005-12-02 at 14:07 +0100, Luis Miguel Morillas wrote:
> Mensaje citado por Han-Wen Nienhuys <hanwen at xs4all.nl>:

> > I'm looking for a package that will translate a minidom tree into 
> > something which  is native python, i.e. translate
> > 
> > <bar>
> >     <bla>
> >        <foo id="1" />
> >        <foo id="2" />
> >     </bla>
> > </bar>
> > 
> > into a python object, for which the following holds
> > 
> >     bar.bla[1].id == "2"
> > 
> > 
> > Of course,  I would have to supply a mapping from names like "bar" and 
> > "bla" to my own classes (probably deriving from xml.node).
> > 
> > Does such a thing exist?
> > 
> > 
> 
> Yes, Try Amara (http://uche.ogbuji.net/tech/4suite/amara/)
> 
> <monty>
>   <python spam="eggs">What do you mean "bleh"</python>
>   <python ministry="abuse">But I was looking for argument</python>
> </monty>
> 
> Becomes a data structure such that you can write:
> 
> binding.monty.python.spam
> 
> In order to get the value "eggs" or
> 
> binding.monty.python[1]

Thanks, Luis.

Yep, and 'bar.bla[1].id == "2"' would work out of the box with Amara.

One question, Han-Wen, do you have to use minidom as the source, or can
you go from straight XML?  Just seems unnecessary to parse to minidom
and then bind.


-- 
Uche Ogbuji                               Fourthought, Inc.
http://uche.ogbuji.net                    http://fourthought.com
http://copia.ogbuji.net                   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/



More information about the XML-SIG mailing list