Skip to content

xml backend does not follow 'the spec' #62

@ssato

Description

@ssato

XML backend does not follow 'the spec', http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html such as xmltodict (https://github.com/martinblech/xmltodict) looks so.

In [1]: import anyconfig.backend.xml as X, xml.etree.cElementTree as ET

In [2]: X.elem_to_container(ET.XML("<e/>"), dict, {})
Out[2]: {'e': {}}

In [3]: X.elem_to_container(ET.XML("<e>text</e>"), dict, {})
Out[3]: {'e': 'text'}

In [4]: X.elem_to_container(ET.XML("<e name='value'/>"), dict, {})
Out[4]: {'e': {'@attrs': {'name': 'value'}}}

In [5]: X.elem_to_container(ET.XML('<e name="value">text</e>'), dict, {})
Out[5]: {'e': {'@attrs': {'name': 'value'}, '@text': 'text'}}

In [6]: X.elem_to_container(ET.XML('<e><a>text</a><b>text</b></e>'), dict, {})
Out[6]: {'e': {'@children': [{'a': 'text'}, {'b': 'text'}]}}

In [7]: X.elem_to_container(ET.XML('<e><a>text</a><a>text</a></e>'), dict, {})
Out[7]: {'e': {'@children': [{'a': 'text'}, {'a': 'text'}]}}

In [8]: X.elem_to_container(ET.XML('<e> text <a>text</a></e>'), dict, {})
Out[8]: {'e': {'a': 'text'}}

In [9]:
Pattern XML JSON Access
1 <e/> "e": null o.e
2 <e>text</e> "e": "text" o.e
3 <e name="value" /> "e":{" @name": "value"} o.e["@name"]
4 <e name="value">text</e> "e": { "@name": "value", "#text": "text" } o.e["@name"] o.e["#text"]
5 <e> <a>text</a> <b>text</b> </e> "e": { "a": "text", "b": "text" } o.e.a o.e.b
6 <e> <a>text</a> <a>text</a> </e> "e": { "a": ["text", "text"] } o.e.a[0] o.e.a[1]
7 <e> text <a>text</a> </e> "e": { "#text": "text", "a": "text" } o.e["#text"] o.e.a

from http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions