You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a new custom class that inherits from the XMLRenderer class as follows (the lines between the arrows are the new ones I've added):
class CustomXmlRenderer(XMLRenderer):
item_tag_name = 'PHONE_NUMBER'
def _to_xml(self, xml, data):
...
elif isinstance(data, dict):
for key, value in six.iteritems(data):
--->if isinstance(value, list):<---
--->self._to_xml(xml, value)<---
--->continue<---
xml.startElement(key, {})
self._to_xml(xml, value)
xml.endElement(key)
I modified the first elif statement, adding a new condition that checks if the value is a List, to then create tags with the same name for each value of the List, and finally I added a continue to go on to the next item and avoid create more tags with the values of the list.
I Hope to help anyone who has got the same task that I had, and doesn't know what to do, or at least saven them some time
I don't know if it could be intagrated with the main project but I'll be watching :)
The text was updated successfully, but these errors were encountered:
Hello and thanks for posting this. Had a similar issue where I was serializing a nested list in list of items. As the nested list has to have a different element to start with (item_tag_name), my modification looks as following.
When I pass a Python Dict like this to the renderer:
The library will return the following XML struct:
But I needed two 'PHONE_NUMBER' tags (that tag 'list-item' is not really useful), one for each value of the list, just like this:
I FOUND THIS WALKAROUND
Create a new custom class that inherits from the XMLRenderer class as follows (the lines between the arrows are the new ones I've added):
I modified the first elif statement, adding a new condition that checks if the value is a List, to then create tags with the same name for each value of the List, and finally I added a continue to go on to the next item and avoid create more tags with the values of the list.
I Hope to help anyone who has got the same task that I had, and doesn't know what to do, or at least saven them some time
I don't know if it could be intagrated with the main project but I'll be watching :)
The text was updated successfully, but these errors were encountered: