On Wed, Jun 16, 2010 at 10:43 AM, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Wed, Jun 16, 2010 at 10:46 AM, abhijeet thatte > <abhijeet.tha...@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.
-- http://mail.python.org/mailman/listinfo/python-list