Introduction
This module allows one to marshal simple Python data types into a custom XML format. The Marshaller and Unmarshaller classes can be subclassed in order to implement marshalling into a different XML DTD. Original Authors are XML-SIG (xml-sig@python.org).
Fully compatible with PyXML implementation, enables namespace support for XML Input/Output.
Implemented with lxml
Installation
python setup.py install
Testing
python setup.py test
Usage
For simple serialisation and unserialisation:
>>> from xml_marshaller import xml_marshaller
>>> xml_marshaller.dumps(['item1', {'key1': 1, 'key2': 'string'}])
'<marshal><list id="i2"><string>item1</string><dictionary id="i3"><string>key1</string><int>1</int><string>key2</string><string>string</string></dictionary></list></marshal>'
>>> xml_marshaller.loads(xml_marshaller.dumps(['item1', {'key1': 1, 'key2': 'string'}]))
['item1', {'key2': 'string', 'key1': 1}]
Can works with file like objects:
>>> from xml_marshaller import xml_marshaller
>>> from StringIO import StringIO
>>> file_like_object = StringIO()
>>> xml_marshaller.dump('Hello World !', file_like_object)
>>> file_like_object.seek(0)
>>> file_like_object.read()
'<marshal><string>Hello World !</string></marshal>'
>>> file_like_object.seek(0)
>>> xml_marshaller.load(file_like_object)
'Hello World !'
xml_marshaller can also output xml with qualified names:
>>> from xml_marshaller import xml_marshaller
>>> xml_marshaller.dumps_ns('Hello World !')
'<marshal:marshal xmlns:marshal="http://www.erp5.org/namespaces/marshaller"><marshal:string>Hello World !</marshal:string></marshal:marshal>'
You can also use your own URI:
>>> from xml_marshaller.xml_marshaller import Marshaller
>>> marshaller = Marshaller(namespace_uri='http://my-custom-namespace-uri/namespace')
>>> marshaller.dumps('Hello World !')
'<marshal:marshal xmlns:marshal="http://my-custom-namespace-uri/namespace"><marshal:string>Hello World !</marshal:string></marshal:marshal>'
History
1.0.2 (2019-02-25)
Python 2 fixups.
1.0.1 (2018-11-12)
Fix changelog.
1.0 (2018-11-12)
Stop distinguish unicode and bytes and always return ‘str’
0.10 (2018-09-12)
Add support for Python 3
0.9.7 (2010-10-30)
Enhance egg folder structure [nicolas Delaby]
Improve tests [nicolas Delaby]
add XSD Schema [nicolas Delaby]
0.9.6 (2010-10-12)
[fix] Support boolean transformation [Nicolas Delaby]
0.9.5 (2010-09-01)
[fix] Formatting of documentation [Lukasz Nowak]
0.9.4 (2010-09-01)
[fix] Instances are now correctly unmarshalled. [Cedric de Saint Martin]
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file xml_marshaller-1.0.2.tar.gz.
File metadata
- Download URL: xml_marshaller-1.0.2.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42f0402cb0c3f28e67650e59e1b7a66e169d2ba8dcc9d58a42925a4a61aaa893
|
|
| MD5 |
54a010c29d3b0e26e4b3d5ef6f5d6d5a
|
|
| BLAKE2b-256 |
eeb8f97f1c4a39f89bf2a3571b7c14f7b6108e7f4b2253931a1b9e09a86ecd74
|