dict2xml

1.7.8 · active · verified Sat Apr 11

dict2xml is a small Python utility designed to convert a Python dictionary into an XML string. It is actively maintained, with frequent minor releases. The current version is 1.7.8.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert a nested Python dictionary into an XML string using the `dict2xml` function. It uses the `wrap` parameter to specify a root element and `indent` for readability.

from dict2xml import dict2xml

data = {
    'root_element': {
        'item1': 123,
        'item2': [
            {'sub_item_a': 'hello'},
            {'sub_item_b': 'world'}
        ],
        'item3': {
            'nested_value': 'example'
        }
    }
}

xml_string = dict2xml(data, wrap='root', indent='  ')
print(xml_string)

view raw JSON →