d = {"a":"a1234","b":"b5678","c":"c4554545"}
Tried converting this dictionary d
to xml
, as below
<?xml version="1.0" encoding="UTF-8" ?>
<test>
<a>a1234</a>
<b>b5678</b>
<c>c4554545</c>
</test>
Code:
from dicttoxml import dicttoxml
xml = dicttoxml(d, custom_root='test', attr_type=False)
# Above 'xml' is of type bytes here
xml = xml.decode("utf-8") # Converting bytes to string
print(xml) # prints, <?xml version="1.0" encoding="UTF-8" ?><test><a>a1234</a><b>b5678</b><c>c4554545</c></test>
Tried printing above xml output with pretty print, but end up obtaining below (excludes <?xml version
)
<test>
<a>a1234</a>
<b>b5678</b>
<c>c4554545</c>
</test>
How to pretty print as below ?
<?xml version="1.0" encoding="UTF-8" ?>
<test>
<a>a1234</a>
<b>b5678</b>
<c>c4554545</c>
</test>