osdir.com
mailing list archive
Mozy Online Backup: 2GB Free. Automatic. Secure.

Subject: Re: automatically building Python data structures from DOM trees? - msg#00007

List: python.xml

Date: Prev Next Index Thread: Prev Next Index
Well, why don't you try my XML Toolkit
http://www.gnucitizen.org/data/download/xt-0.7.BETA.py

This is what to do

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

<bla>
<foo id="1" />
<foo id="2" />
</bla>
</bar>''')

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>'))
element['bla'].append(Element('foo'))

Cheers

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?
>
>
>
>

_______________________________________________
XML-SIG maillist - XML-SIG@xxxxxxxxxx
http://mail.python.org/mailman/listinfo/xml-sig



Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

automatically building Python data structures from DOM trees?

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? -- Han-Wen Nienhuys - hanwen@xxxxxxxxx - http://www.xs4all.nl/~hanwen _______________________________________________ XML-SIG maillist - XML-SIG@xxxxxxxxxx http://mail.python.org/mailman/listinfo/xml-sig

Next Message by Date: click to view message preview

Re: automatically building Python data structures from DOMtrees?

Han-Wen Nienhuys wrote: > 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? does it has to be a minidom tree? if not, you can find plenty of alternatives under the "data bindings" section in this article: http://www.xml.com/pub/a/2004/10/13/py-xml.html </F> _______________________________________________ XML-SIG maillist - XML-SIG@xxxxxxxxxx http://mail.python.org/mailman/listinfo/xml-sig

Previous Message by Thread: click to view message preview

automatically building Python data structures from DOM trees?

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? -- Han-Wen Nienhuys - hanwen@xxxxxxxxx - http://www.xs4all.nl/~hanwen _______________________________________________ XML-SIG maillist - XML-SIG@xxxxxxxxxx http://mail.python.org/mailman/listinfo/xml-sig

Next Message by Thread: click to view message preview

Re: automatically building Python data structures from DOMtrees?

Han-Wen Nienhuys wrote: > 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? does it has to be a minidom tree? if not, you can find plenty of alternatives under the "data bindings" section in this article: http://www.xml.com/pub/a/2004/10/13/py-xml.html </F> _______________________________________________ XML-SIG maillist - XML-SIG@xxxxxxxxxx http://mail.python.org/mailman/listinfo/xml-sig
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by