Templating utilities
Project description
Neodict2XML
Neomyte's dict to XML converter
Example:
>>> from neodict2xml import dict2xml
>>> test_dict = {\
'test': {\
'plop': ({'attr': 'brrr'}, 'lol'),\
'lol': [\
'hello',\
'world'\
],\
'deep': {\
'deeper': 1\
},\
'test2': [\
{ 'foo': 'bar' },\
( { 'id': 2 }, { 'foo': 'rab' } )\
],\
'test3': ( { 'class': 'foo.Bar' }, )\
'test4': None,\
'test5': {},\
'test6': ( { 'class': 'foo.Bar' }, None ),\
'test7': ( { 'class': 'foo.Bar' }, {} )\
}\
}
>>> xml = dict2xml.from_dict(test_dict)
>>> print(dict2xml.prettify(xml))
<?xml version="1.0" ?>
<test>
<plop attr="brrr">lol</plop>
<lol>hello</lol>
<lol>world</lol>
<deep>
<deeper>1</deeper>
</deep>
<test2>
<foo>bar</foo>
</test2>
<test2 id="2">
<foo>rab</foo>
</test2>
<test3 class="foo.Bar"/>
<test4/>
<test5/>
<test6 class="foo.Bar"/>
<test7 class="foo.Bar"/>
</test>
>>> from neodict2xml import dict2xml
>>> test_xml = test_xml = '''
... <test>
... <plop attr="brrr">lol</plop>
... <lol>hello</lol>
... <lol>world</lol>
... <lol2>hello</lol2>
... <lol2>world</lol2>
... <lol2>foo</lol2>
... <lol2>bar</lol2>
... <deep>
... <deeper>
... 1
... </deeper>
... </deep>
... <test2>
... <foo>bar</foo>
... </test2>
... <test2 id="2">
... <foo>bar</foo>
... </test2>
... <test3 class="foo.Bar" />
... <test4 />
... </test>
... '''
>>> dict2xml.from_xml(test_xml)
{'test': {'plop': ({'attr': 'brrr'}, 'lol'), 'lol': ['hello', 'world'], 'lol2': ['hello', 'world', 'foo', 'bar'], 'deep': {'deeper': '1'}, 'test2': [{'foo': 'bar'}, ({'id': '2'}, {'foo': 'bar'})], 'test3': ({'class': 'foo.Bar'},), 'test4': None}}
Contributors
- Emmanuel Pluot (aka. Neomyte)
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[Unreleased]
[0.0.3] - 2022-03-10
Added
- Add from_xml function
Changed
- None is now considered the same as an empty dict in from_dict
- Fix setup doc and url
[0.0.2] - 2021-11-24
Changed
- Handle subelement with attributes but no value
- Update Readme
[0.0.1] - 2021-11-24
Added
- dict2xml module
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Neodict2XML-0.0.3.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for Neodict2XML-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cec20dcf4e1477f138ea0efaae8b94d74e484fbd6dc1c417bed7a64513f26251 |
|
MD5 | c86cb51deb9821c8801d1da42e93a6ec |
|
BLAKE2b-256 | 1f6dd118d115efab2761d35f87d84c5079af0505720b9b6ea75d66d592a1c83b |