Skip to main content

Simple xml parse and build lib.

Project description

Brief

Latest Version License Downloads

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

Installation

  • Use pip

$ pip install lazyxml
  • Use easy_install

$ easy_install lazyxml
  • Use source. Download the project source and decompress, then do the following command.

$ cd lazyxml
$ python setup.py install

Examples

  • 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

Documentation

See docs in pythonhosted or docs in readthedocs

Changelog

See changelog

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.2.tar.gz (17.0 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for lazyxml-1.2.tar.gz
Algorithm Hash digest
SHA256 51f15e1d1412868d429a1a9ee9e8d6d3ce733e21c34a6f56543aa505165c300b
MD5 13fd03b04928b3209375c41c3ee0fdf9
BLAKE2b-256 6f51cf1fc36a2087408b108cfacc61365c98eb5ca9b3fc83b38199b9e8b26489

See more details on using hashes here.

Supported by

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