This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

lxml wrapper that simplifies xml generation code.

Project Description

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'
         )
     )
Release History

Release History

This version
History Node

0.4

History Node

0.3.7

History Node

0.3.6

History Node

0.3.5

History Node

0.3.4

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3

History Node

0.2b

History Node

0.1b

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting