item_func usage - end tag mismatch
robbincatz opened this issue · 3 comments
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!
Hi robbinatz, that's definitely a bug. I'll take a look at it ASAP and get back to you.
Brilliant, thanks for the quick response.
Issue is fixed in version 1.7.4. Thank you for identifying and reporting this issue!