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.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 details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Neodict2XML-0.0.4.tar.gz.
File metadata
- Download URL: Neodict2XML-0.0.4.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3c54a2366d644536f416fc550a4571b7ee33e945b720790f2999abb5032ccf2
|
|
| MD5 |
d6d26910ebf9f9fc4ca74fde5682a432
|
|
| BLAKE2b-256 |
2f79bae11693fb4398e3b651be8b40eb6ca421ec58b0b72b3f63340c03424a36
|
File details
Details for the file Neodict2XML-0.0.4-py3-none-any.whl.
File metadata
- Download URL: Neodict2XML-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6462af59f2541232756a72ccc5af87c19842ffb7e5f4f14a9a1391aee5d84685
|
|
| MD5 |
8dca64146d93b2623bfda979afc19c35
|
|
| BLAKE2b-256 |
53aff2d12bdc06dccfcb9f1791153719059c0a85cdc243605891adf4448c4973
|