<br><br><div class="gmail_quote">On Wed, Jun 16, 2010 at 10:43 AM, Ian Kelly <span dir="ltr"><<a href="mailto:ian.g.kelly@gmail.com">ian.g.kelly@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Wed, Jun 16, 2010 at 10:46 AM, abhijeet thatte<br>
<<a href="mailto:abhijeet.thatte@gmail.com">abhijeet.thatte@gmail.com</a>> wrote:<br>
> I am parsing some hardware format which finally I need to convert in xml.<br>
> The intermediate step is dicts.<br>
> So, the structure looks like this:<br>
> {chip_name:'myChip',chip_clock:'3.07',chip_peripherals:{peripheral1:{mode:'mode1',register:{}},peripheral2:{....},peripheral3:{...}}}<br>
> I think this example gives good insight into kind of dict structure I am<br>
> having. Now I want to have every dict tag as xml tag with hierarchy<br>
> maintained.<br>
<br>
</div>You could traverse the dict, using xml.etree.ElementTree.TreeBuilder<br>
to build up an element tree, then use ElementTree.write() to generate<br>
the xml file.  It's not clear why you need the dict, though.  Why not<br>
just use the element tree as your intermediate representation?<br>
<br>
Cheers,<br>
<div><div></div><div class="h5">Ian<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a></div></div></blockquote><div> </div></div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<div><div>>>> Thanks Ian. </div></div></blockquote><div>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. </div>
</span>