Skip to content

item_func usage - end tag mismatch #46

Description

@robbincatz

I'm trying to change a list of dicts to xml. In the xml I need the item name to be 'module' instead of the default 'item' so have been trying to use the new item_func argument to dicttoxml to achieve this. Example of my list:
[{"key1": "1", "key2": "2", "key3": "3"}, {"key1": "1", "key2": "2", "key3": "3"}]

The following code nearly works but the module/item tags are incorrect i.e. the resulting xml has opening 'module' tags but closing 'item' tags:

import dicttoxml
a = [{"key1": "1", "key2": "2", "key3": "3"}, {"key1": "1", "key2": "2", "key3": "3"}]
f = lambda x: 'module'
output = dicttoxml.dicttoxml(a, attr_type=False, custom_root='xml', item_func=f)
print(output)
<?xml version="1.0" encoding="UTF-8" ?><xml><module><key3>3</key3><key2>2</key2><key1>1</key1></item><module><key3>3</key3><key2>2</key2><key1>1</key1></item></xml>

(May be easier to spot issue from xml output substring: <module><key3>3</key3><key2>2</key2><key1>1</key1></item> - see start 'module' tag & end 'item' tag)

Is this a bug in item_func? Or is my use case just not supported?

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions