from dicttoxml import dicttoxml from xml.dom.minidom import parseString def custom_item_func(item): return 'review' docs = { "reviews": [ { "id": 1, "text": "The SmartHome Mini is a compact, powerful, and user-friendly smart home hub. It offers great value for its price." }, { "id": 2, "text": "The SmartHome Mini is a decent entry-level smart home hub, but it has some connectivity issues and the app needs improvement." }, { "id": 3, "text": "Despite being affordable and compact, the SmartHome Mini's performance is disappointing, with poor voice command interpretation and unreliable device connections." } ] } # Convert the dictionary to XML xml_output = dicttoxml(docs, attr_type=False, root=False, item_func=custom_item_func) # Parse the XML string dom = parseString(xml_output) # Pretty-print the XML with indentation and spaces pretty_xml = dom.toprettyxml(indent=" ") # Print the pretty-printed XML print(pretty_xml)