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

Petko Petkov ppetkov at gnucitizen.org
Fri Dec 2 13:57:50 CET 2005

Well, why don't you try my XML Toolkit

This is what to do

import xt
element = xt.Element().loadstring('''<bar>

       <foo id="1" />
       <foo id="2" />

element = xt.Element().loadfile('myfile.xml')

for e in element:
	print e.name
	print e.namespace

print element

print element['bla'].findall('foo')
print element['bla']['foo'].attributes['id'].namesace
element['bla']['foo'].attributes['id'] = 'This is a new id'

for e in element['bla'].findall('foo'):
	print e.attributes['id'].value

element['bla'].append(Element().loadstring('<foo>Another bla<foo>'))


Han-Wen Nienhuys wrote:
> Hi,
> 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?

More information about the XML-SIG mailing list