Converts Python dictionaries to XML, JSON to XML, compiles XML, converts XML to JSON, and a lot more!
Project description
XMLParsing is an easy-to-use Python 3 parser for compiling, transforming, encoding and decoding XML files and text.
XMLParsing installation:
Run this in your command prompt/shell
pip install xmlparsing
XMLParsing convert dictionary:
xmlparsing.dict2xml
INPUT:
import xmlparsing
myDict = {"numbers": [1, 2, 3], "letters": ["a", "b", "c"], "text": "Lorem ipsum dolor sit amet"}
print(xmlparsing.dict2xml(myDict, title="all"))
OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<all>
<numbers>
<item i="0">1</item>
<item i="1">2</item>
<item i="2">3</item>
</numbers>
<letters>
<item i="0">a</item>
<item i="1">b</item>
<item i="2">c</item>
</letters>
<text>Lorem ipsum dolor sit amet</text>
</all>
In the above, you can see that the "title" attribute in xmlparsing.dict2xml is what defines the tag that your entire document will be inside.
XMLParsing convert JSON file:
xmlparsing.jsonfil2xml
INPUT:
import xmlparsing
print(xmlparsing.jsonfile2xml('myStorage.json')
The file "myStorage.json":
{
"numbers": [
1,
2,
3
],
"letters": [
"a",
"b",
"c"
],
"text": "Lorem ipsum dolor sit amet"
}
OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<myStorage>
<numbers>
<item i="0">1</item>
<item i="1">2</item>
<item i="2">3</item>
</numbers>
<letters>
<item i="0">a</item>
<item i="1">b</item>
<item i="2">c</item>
</letters>
<text>Lorem ipsum dolor sit amet</text>
</myStorage>
XMLParsing format XML:
xmlparsing.formatxml
INPUT:
import xmlparsing
print(xmlparsing.formatxml('<?xml version="1.0" encoding="UTF-8"?> <all> <numbers> <item i="0">1</item> <item i="1">2</item> <item i="2">3</item> </numbers> <letters> <item i="0">a</item> <item i="1">b</item> <item i="2">c</item> </letters> <text>Lorem ipsum dolor sit amet</text> </all>'))
OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<all>
<numbers>
<item i="0">1</item>
<item i="1">2</item>
<item i="2">3</item>
</numbers>
<letters>
<item i="0">a</item>
<item i="1">b</item>
<item i="2">c</item>
</letters>
<text>Lorem ipsum dolor sit amet</text>
</all>
The code above cleans up XML.
XMLParsing convert XML to dictionary:
xmlparsing.xml2dict
INPUT:
import xmlparsing
print(xmlparsing.xml2dict('''
<all>
<numbers>
<item i="0">1</item>
<item i="1">2</item>
<item i="2">3</item>
</numbers>
<letters>
<item i="0">a</item>
<item i="1">b</item>
<item i="2">c</item>
</letters>
<text>Lorem ipsum dolor sit amet</text>
</all>
'''))
OUTPUT:
{'all': {'numbers': {'item': [{'@i': '0', '#text': '1'}, {'@i': '1', '#text': '2'}, {'@i': '2', '#text': '3'}]}, 'letters': {'item': [{'@i': '0', '#text': 'a'}, {'@i': '1', '#text': 'b'}, {'@i': '2', '#text': 'c'}]}, 'text': 'Lorem ipsum dolor sit amet'}}
XMLParsing convert XML to JSON:
xmlparsing.xml2json
INPUT:
import xmlparsing
print(xmlparsing.xml2json('''
<all>
<numbers>
<item i="0">1</item>
<item i="1">2</item>
<item i="2">3</item>
</numbers>
<letters>
<item i="0">a</item>
<item i="1">b</item>
<item i="2">c</item>
</letters>
<text>Lorem ipsum dolor sit amet</text>
</all>
'''))
OUTPUT:
{
"all": {
"letters": {
"item": [
{
"#text": "a",
"@i": "0"
},
{
"#text": "b",
"@i": "1"
},
{
"#text": "c",
"@i": "2"
}
]
},
"numbers": {
"item": [
{
"#text": "1",
"@i": "0"
},
{
"#text": "2",
"@i": "1"
},
{
"#text": "3",
"@i": "2"
}
]
},
"text": "Lorem ipsum dolor sit amet"
}
}
THE END!
Enjoy using XMLParsing!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xmlparsing-0.0.1.tar.gz
.
File metadata
- Download URL: xmlparsing-0.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73b09fa85cc21401c8bbe9fe52e02a368b892a13c028ed4bcb546c6aa07bb6af |
|
MD5 | 9aedbc012c0bdee320b84af1b5dd94ff |
|
BLAKE2b-256 | 4d9b7df154f1accaf0fbac180c68a924c9caf832635df9ae447527cd08ec0d0d |
File details
Details for the file xmlparsing-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: xmlparsing-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3d32ccbaa5fcefb23ff1931809c9f084f06fae9e45a8bddc01371ff58a43cff |
|
MD5 | 8ba4bc361405d85c109e95509ffafd0a |
|
BLAKE2b-256 | bba667ce3ed37e69230ed12a086e5090e57ad9ca460b4bf8f80ad85568947a7c |