Need to parse python dictionaries into xml

Stefan Behnel stefan_ml at behnel.de
Wed Jun 16 13:57:48 EDT 2010


Hi, please avoid top-posting.

abhijeet thatte, 16.06.2010 18:46:
> On Tue, Jun 15, 2010 at 11:09 PM, Stefan Behnel wrote:
>> abhijeet thatte, 16.06.2010 03:05:
>>> I am a novice Python user. I am using Python to parse some hardware
>>> specifications and create xml files from them.
>>> I generate dict of really huge sizes. (I am parsing some 10,000 register
>>> definitions.)
>>
>> Why do you need these intermediate dicts?
>>
>>>   So, it looks like : {elem1,elem2, elem3,dict1,{elem4,elem5, dict2 {elem6,
>>> elem7, dict3{.....}}}}.
>>>
>>
>> What is this hierarchy of dicts mapping to what?
>>
>> It's always best to provide a short extract of a real example rather than
>> something you made up.
 >
> 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:{...}}}

With "real example" I meant real code and real (or close to real) data. The 
above is not a valid Python dictionary. I assume the keys are supposed to 
be strings?


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

What is name of the root element that you want?

You should start by writing down the XML structure that you want to build 
for the above dict. That will make it clear what needs to be done.

Stefan




More information about the Python-list mailing list