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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for lazyxml-1.2.1.tar.gz
Algorithm Hash digest
SHA256 bb1b274f9c7a75f60a9aa4d088a9d7200948a43323f2385081296cdb7e09cb07
MD5 f095b9a9449625be6a56da194eb2d3f2
BLAKE2b-256 ebca9fe2223845fb0e6637a99fe485fc3535e471b12e4a016332c9cabf0264a6

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