sanand0 / xmljson

xmlsjon converts XML into Python dictionary structures (trees, like in JSON) and vice-versa.
MIT License
121 stars 33 forks source link

mapping to list of lists #6

Closed bsdz closed 7 years ago

bsdz commented 8 years ago

Hi. Thanks for a great module.

I notice when one does a round-trip from a dictionary containing a list of lists, the result is a dictionary containing a list of strings. This is using the Parker convention.

from xml.etree.ElementTree import Element, tostring, fromstring
from xmljson import parker, Parker

xml_str = tostring(parker.etree({'A':[[1,2],[3,4]]}, root=Element('data')))
Parker(dict_type=dict).data(fromstring(xml_str))
{'A': ['[1, 2]', '[3, 4]']}
sanand0 commented 7 years ago

@bsdz when we convert {'A':[[1,2],[3,4]]} to an XML string using the Parker convention, the library translates that to <A>[1, 2]</A><A>[3, 4]</A>. When converting back, this is translated into a list of strings.

None of the conventions preserve parity for arbitrary data types. Each is a lossy encoding. This library sticks to the defined standards, and interprets the undefined ones as simply as possible.

Were you expecting different results?

PS: Apologies for the huge delay. I'm surprised I missed this.

bsdz commented 7 years ago

Thanks for getting back. Yes I realized the library is constrained by standards. I needed something that could map python objects back and forth between xml and finally resolved to using gnosis xml tools :)