Trying to parse xml-request from some program I've got quite complicated architecture. It is dict of dicts of dict of dict. Some of dicts contains also lists of dicts. But due to too uncomfortable structure my dict contains lots of "garbage" words "begin_"
and "value"
throughout its depth.
For example:
<depart>
<BEGIN_>
<id Value=""/>
<code Value=""/>
<name Value=""/>
<declNameList/>
</BEGIN_>
</depart>
has transformed to
{'depart': {'BEGIN_': {'id': {'Value': ''},
'code': {'Value': ''},
'name': {'Value': ''},
'declNameList': None}}}}}
and I need:
{'depart': {'id': '',
'code': '',
'name': '',
'declNameList': None}}
May you pls help me to remove this trash using full-depth recursion?
At the moment I managed to transform h = {'status': {'BEGIN_': {'statusCode': {'Value': '0'}}}}
to {'status': {'statusCode': {'Value': '0'}}}
by using:
if 'Value' in h['status'].keys():
h['status'] = h['status']['Value']
if 'BEGIN_' in h['status'].keys():
h['status'] = h['status']['BEGIN_']
But I need to apply this kind of filter to the whole dictionary.