How to parse all nodes of given XML to an array in python -


how parse nodes of following xml array in python

<?xml version="1.0"?> <carlist>    <car>      <model>benz</model>       <specifications>        <engine>turbo</engine>         <fueltype>petrol</fueltype>      </specifications>    </car>     <car>      <model>fiat</model>       <specifications>        <engine>diesel</engine>         <fueltype>petrol</fueltype>      </specifications>    </car>  </carlist> 

xmltodict python module makes working xml feel working json

example:

s = """<?xml ... </carlist>""" parsed = xmltodict.parse(s) car in parsed['carlist']['car']:   print(dict(car))  {u'specifications': ordereddict([(u'engine', u'turbo'), (u'fueltype', u'petrol')]), u'model': u'benz'} {u'specifications': ordereddict([(u'engine', u'diesel'), (u'fueltype', u'petrol')]), u'model': u'fiat'} 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -