skip to navigation
skip to content

Not Logged In

lazyxml 1.2.1

Simple xml parse and build lib.

Package Documentation

Brief

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

Warning

Python 2.5 or greater is required.

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

Changelog

See changelog

 
File Type Py Version Uploaded on Size
lazyxml-1.2.1.tar.gz (md5) Source 2014-06-15 17KB
  • Downloads (All Versions):
  • 0 downloads in the last day
  • 27 downloads in the last week
  • 180 downloads in the last month
  • Author: Zonglong Fan
  • Documentation: lazyxml package documentation
  • Home Page: https://github.com/heronotears/lazyxml
  • License:
    The MIT License (MIT)
    
    Copyright (c) 2014 Zonglong Fan
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
  • Platform: any
  • Package Index Owner: heronotears
  • DOAP record: lazyxml-1.2.1.xml