[XML-SIG] Represent XML

Luis Miguel Morillas morillas at gmail.com
Fri Jan 27 17:50:45 CET 2006

2006/1/27, Sbaush <sbaush at gmail.com>:
> Hi all.
> I attach to you a example XML file to parse and the demo of my objective.
> The iptRequest.xml is the file to parse in one mode. I can't parse it.
> The demo.py is my ideal result, manually built, that should be built by
> parsing the XML.
> How can i do to do it?
> Bye all!

Easy, here you have the data you need, then compose your strings :)

import amara
doc = amara.parse('iptRequest.xml')
for table in doc.xml_xpath (u'//table'):
    data = {}
    data['chain'] = table.chain
    data['poli'] = table.policy
    for rule in table.xml_children:
        if not isinstance(rule, unicode):
            for at in rule.xml_attributes.keys ():
                data[at] = eval('rule.'+at)
    print data  #  now build your string



Luis Miguel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/xml-sig/attachments/20060127/207e641a/attachment.html 

More information about the XML-SIG mailing list