Skip to main content

Simple xml parse and build lib.

Project description

Latest Version License Downloads

简单的xml解析/生成库. 类似于simplejson的用法.

使用示例

  • xml转换成python对象

>>> import lazyxml
>>> xml = '<demo><foo>foo</foo><bar>bar</bar></demo>'
>>> lazyxml.loads(xml)
{'bar': 'bar', 'foo': 'foo'}
>>> lazyxml.loads(xml, strip_root=False)
{'demo': {'bar': 'bar', 'foo': 'foo'}}
>>> xml = '<demo><foo>foo</foo><bar>1</bar><bar>2</bar></demo>'
>>> lazyxml.loads(xml)
{'bar': ['1', '2'], 'foo': 'foo'}
  • python对象转换成xml

>>> data = {'demo':{'bar': ['1', '2'], 'foo': '<foo>'}}
>>> lazyxml.dumps(data)
'<?xml version="1.0" encoding="utf-8"?><demo><foo><![CDATA[<foo>]]></foo><bar><![CDATA[1]]></bar><bar><![CDATA[2]]></bar></demo>'
>>> lazyxml.dumps(data, cdata=False)
'<?xml version="1.0" encoding="utf-8"?><demo><foo>&lt;foo&gt;</foo><bar>1</bar><bar>2</bar></demo>'
>>> print lazyxml.dumps(data, indent=' ' * 4)
<?xml version="1.0" encoding="utf-8"?>
<demo>
    <foo><![CDATA[<foo>]]></foo>
    <bar><![CDATA[1]]></bar>
    <bar><![CDATA[2]]></bar>
</demo>
  • 详细用法参见 demo

Changelog

1.1.0 (2014-05-06)

  • First public version

1.0.0 (2014-05-04)

  • Move to github

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

lazyxml-1.1.0.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file lazyxml-1.1.0.tar.gz.

File metadata

  • Download URL: lazyxml-1.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lazyxml-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5c7206ba21c3c674713506e599028ae45c5dc257012f050f0b186cbc870294d1
MD5 2b7893e72b231b4999012af0536f9d8d
BLAKE2b-256 7119a293a739b7bac622ba71c562a37e58f6e25c0c42fa4ff28662ec00cee278

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page