将Python对象转换为XML并再次转换回来。
项目描述
介绍
此模块允许将简单的Python数据类型转换为自定义XML格式。可以通过扩展Marshaller和Unmarshaller类来实现将数据转换为不同的XML DTD。原始作者为XML-SIG(xml-sig@python.org)。
与PyXML实现完全兼容,支持XML输入/输出命名空间。
使用lxml实现
安装
python setup.py install
测试
python setup.py test
用法
对于简单的序列化和反序列化
>>> 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}]
可以与文件对象一起工作
>>> 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还可以输出带有限定名称的XML
>>> 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>'
您还可以使用自己的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>'
历史
1.0.2 (2019-02-25)
Python 2修复。
1.0.1 (2018-11-12)
修复更改日志。
1.0 (2018-11-12)
停止区分Unicode和bytes,并始终返回'str'。
0.10 (2018-09-12)
添加对Python 3的支持
0.9.7 (2010-10-30)
增强鸡蛋文件夹结构 [尼古拉·德尔巴伊]
改进测试 [尼古拉·德尔巴伊]
添加 XSD 架构 [尼古拉·德尔巴伊]
0.9.6 (2010-10-12)
[修复] 支持布尔转换 [尼古拉·德尔巴伊]
0.9.5 (2010-09-01)
[修复] 文档格式化 [卢卡什·诺瓦克]
0.9.4 (2010-09-01)
[修复] 实例现在正确反序列化。 [塞德里克·德·圣马丁]
项目详情
关闭
xml_marshaller-1.0.2.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 42f0402cb0c3f28e67650e59e1b7a66e169d2ba8dcc9d58a42925a4a61aaa893 |
|
MD5 | 54a010c29d3b0e26e4b3d5ef6f5d6d5a |
|
BLAKE2b-256 | eeb8f97f1c4a39f89bf2a3571b7c14f7b6108e7f4b2253931a1b9e09a86ecd74 |