Need to parse python dictionaries into xml

abhijeet thatte abhijeet.thatte at gmail.com
Wed Jun 16 14:46:41 EDT 2010


On Wed, Jun 16, 2010 at 10:43 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:

> On Wed, Jun 16, 2010 at 10:46 AM, abhijeet thatte
> <abhijeet.thatte at gmail.com> wrote:
> > I am parsing some hardware format which finally I need to convert in xml.
> > The intermediate step is dicts.
> > So, the structure looks like this:
> >
> {chip_name:'myChip',chip_clock:'3.07',chip_peripherals:{peripheral1:{mode:'mode1',register:{}},peripheral2:{....},peripheral3:{...}}}
> > I think this example gives good insight into kind of dict structure I am
> > having. Now I want to have every dict tag as xml tag with hierarchy
> > maintained.
>
> You could traverse the dict, using xml.etree.ElementTree.TreeBuilder
> to build up an element tree, then use ElementTree.write() to generate
> the xml file.  It's not clear why you need the dict, though.  Why not
> just use the element tree as your intermediate representation?
>
> Cheers,
> Ian
> --
> http://mail.python.org/mailman/listinfo/python-list
>


> >>> Thanks Ian.
>
Can you suggest a link showing usage of TreeBuilder in such cases. I have
not come across ElementTree till this point. (Started using python 3-4 days
back). So, I thought Dicts were based to store hierarchical format. I am now
checking how to use ElementTree. Any input is welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100616/49d711be/attachment-0001.html>


More information about the Python-list mailing list