1

Is there any way to create xml output that given a multiple OrderedDict like this

data = OrderedDict([
    ...
    ('addresses', OrderedDict([
        ('address', OrderedDict([
            ('city', 'Washington')
        ])),
        ('address', OrderedDict([
            ('city', 'Boston')
        ]))
    ]))
])

When i try this xmltodict covers last address not both.

jackquin
  • 534
  • 1
  • 7
  • 19

1 Answers1

0

That is because you have 2 keys with the same name 'address'..then if you change the both like bellow (address1,address2)...you can access in both.For parse you can use xmltodict

import json
from collections import OrderedDict
from json import loads, dumps
import xmltodict

data = OrderedDict([
    ('addresses', OrderedDict([
        ('address1', OrderedDict([
            ('city', 'Washington')
        ])),
        ('address2', OrderedDict([
            ('city', 'Boston')
        ]))
    ]))
])

print(json.loads(json.dumps(data)))

print(xmltodict.unparse((data)))

result :

enter image description here

GiovaniSalazar
  • 1,999
  • 2
  • 8
  • 15