lxml wrapper that simplifies xml generation code.
Project description
This wrapper simplifies your Python xml generation code.
Example XML:
<root attrib="10">
text
<child attrib="">
childtext
</child>
tail
</root>
New way:
E('root', attrib=10).add(
'text',
E('child', attrib=None).add(
'childtext'),
'tail')
Old way:
root = Element('root', attrib=str(10)) # cast to str
root.text = 'text'
child = SubElement(root, 'child', attrib=value or "") # change None to empty string
child.text = 'childtext'
child.tail = 'tail'
Now with .add_if and .add_for methods:
E('root').add_if(1==1, E('child')) -> <root><child /></root>
E('root').add_if(1==0, E('child')) -> <root/>
E('root').add_for([1,2], lambda item: E('item', attr=item)) -> <root><item attr="1"/><item attr="2"/></root>
Example XML:
<root attrib="10">
text
<child attrib="">
childtext
</child>
tail
</root>
New way:
E('root', attrib=10).add(
'text',
E('child', attrib=None).add(
'childtext'),
'tail')
Old way:
root = Element('root', attrib=str(10)) # cast to str
root.text = 'text'
child = SubElement(root, 'child', attrib=value or "") # change None to empty string
child.text = 'childtext'
child.tail = 'tail'
Now with .add_if and .add_for methods:
E('root').add_if(1==1, E('child')) -> <root><child /></root>
E('root').add_if(1==0, E('child')) -> <root/>
E('root').add_for([1,2], lambda item: E('item', attr=item)) -> <root><item attr="1"/><item attr="2"/></root>
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.5.tar.gz
(2.4 kB
view hashes)
Built Distribution
Close
Hashes for lxml-wrapper-0.3.5.linux-i686.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71cd5a470e30fbbd3bbfdcf6ad65d34208952bca8e05e1028d8f1ff09915fa37 |
|
MD5 | d8c867b23cdff607fe85b68739842512 |
|
BLAKE2b-256 | 4d6f1bc7671af6aa3bcecdb42f3fc92e8ee756f7c1809a56a612fd31064d3374 |