XML : ET parsing of XML in Python

I have an xml file and I am trying to parse it with python and retrieve the k,v pairs with ET library.

Here is the structure of the xml file:

<dict><dict><dict> <key>Prod_ID</key><integer>369</integer> <key>Prod_Name</key><string>Glass Crucible</string> <key>Prod_Company</key><string>IVar</string> ... </dict></dict><dict> This is my python code:

  fn = 'file.xml'  stuff = ET.parse(fn)  all = stuff.findall('dict/dict/dict')  dict1 = all[0]  print dict1.items    

I see that ET parses fine and puts each of the 3rd dict nodes in a list as I want. However I want to retrieve the first of the items in the list which is a dictionary and print it. So I assigned it to dict1. When I tried to print it, I am not getting the following output, instead of real values of the items in the dictionary. What am I doing wrong?

>

No comments:

Post a Comment