lxml wrapper that simplifies xml generation code.
Project description
- Info:
See github for the latest source.
About
This wrapper simplifies your Python xml generation code.
Changes
add_if
E('root').add_if(1==1, E('child')) # <root><child /></root> E('root').add_if(1==0, E('child')) # <root/>
add_for
E('root').add_for([1,2], lambda item: E('item', attr=item)) # <root><item attr="1"/><item attr="2"/></root>
Dependencies
lxml http://codespeak.net/lxml/
Installation
pip install lxml-wrapper
Examples
XML
<root atr="100"> text1 <child atr="atr"> <superchild atr="">sctext1</superchild> tail1 tail2 </child> tail <child atr="">text</child> </root>
Old way
root = Element('root', atr=str(100)) root.text = 'text1' child = SubElement(root, 'child', atr="atr") superchild = SubElement(root, 'superchild', atr="" if value is None else value) superchild.text = 'sctext1' superchild.tail = 'tail1' superchild.tail += 'tail2' child.tail = 'tail' child = SubElement(root, 'child', atr="") child.text = 'text'
New way
root = E('root', atr=100).add( 'text1', E('child', atr="atr").add( E('superchild', atr=None).add('sctext1'), 'tail1', 'tail2' ), 'tail', E('child', atr="").add( 'text' ) )
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lxml-wrapper-0.3.7.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for lxml-wrapper-0.3.7.macosx-10.7-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e32f7992863059e5f88a72489fd54ac81655b7e418ed8ddba57a27f01e67051f |
|
MD5 | f162fd813549420a2cb551f3dfb77eb4 |
|
BLAKE2b-256 | 2b826f7d6e3e5ea56704dc9304dcdd18ecb220aa8c813c36841153182ba6f062 |