Templating utilities
Project description
Neodict2XML
Neomyte's dict to XML converter
<ins>Example:<ins>
>>> 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.4] - 2022-03-12
Changed
- Deep copy dict entry to from_dict to prevent unwanted modification to the original data
[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.4.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for Neodict2XML-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6462af59f2541232756a72ccc5af87c19842ffb7e5f4f14a9a1391aee5d84685 |
|
MD5 | 8dca64146d93b2623bfda979afc19c35 |
|
BLAKE2b-256 | 53aff2d12bdc06dccfcb9f1791153719059c0a85cdc243605891adf4448c4973 |