skip to navigation
skip to content

lxml-wrapper 0.3

lxml wrapper that simplifies xml generation code.

Downloads ↓

Latest Version: 0.3.5

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>
 
File Type Py Version Uploaded on Size # downloads
lxml-wrapper-0.3.tar.gz (md5) Source 2010-03-17 2KB 368