1
<things>
    <fruit>apple</fruit>
    <hardware>mouse</hardware>
...
</things>

Turn it into:

{'things':[{'fruit':'apple'}, {'hardware':'mouse'}]}

Is there an easy way to do this? Thanks.

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • Duplicate. All of these: http://stackoverflow.com/search?q=%5Bpython%5D+xml+dictionary. Specifically, this http://stackoverflow.com/questions/2148119/how-to-convert-a-xml-string-to-a-dictionary-in-python – S.Lott Feb 05 '10 at 11:02
  • if you know how to use xpath well, you can process xml as if it is a list, or a dictionary – vtd-xml-author Feb 05 '10 at 19:30

1 Answers1

1

there's a nice recipe for that here:

http://code.activestate.com/recipes/570085/

another good one is here:

http://code.activestate.com/recipes/522991/

user262976
  • 1,994
  • 12
  • 7