Skip to main content

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>

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

lxml-wrapper-0.3.2.tar.gz (2.5 kB view hashes)

Uploaded Source

Supported by

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