4 Summary: Pythonic way to create xml files
5 Home-page: http://pypi.python.org/pypi/xmlbuilder
7 Author-email: koder_dot_mail@gmail_dot_com
9 Download-URL: http://pypi.python.org/pypi/xmlbuilder
10 Description: Example of usage:
14 from __future__ import with_statement
15 from xmlbuilder import XMLBuilder
16 x = XMLBuilder(format=True)
19 [x << ('node',{'val':i}) for i in range(10)]
27 <node val="0" />
28 <node val="1" />
29 <node val="2" />
30 <node val="3" />
31 <node val="4" />
32 <node val="5" />
33 <node val="6" />
34 <node val="7" />
35 <node val="8" />
36 <node val="9" />
40 Mercurial repo:http://hg.assembla.com/MyPackages/
44 `XMLBuilder` is simple library build on top of `ElementTree.TreeBuilder` to
45 simplify xml files creation as much as possible. Althow it can produce
46 structured result with identated child tags. `XMLBuilder` use python `with`
47 statement to define xml tag levels and `<<` operator for simple cases -
48 text and tag without childs.
50 First we need to create xmlbuilder
52 from xmlbuilder import XMLBuilder
53 # params - encoding = 'utf8',
54 # builder = None, - ElementTree.TreeBuilder
55 # tab_level = None, - current tab l;evel - for formatted output only
56 # format = False, - create formatted output
57 # tab_step = " " * 4 - indentation step
61 Use `with` statement to make document structure
62 #create and open tag 'root_tag' with text 'text' and attributes
63 with xml.root_tag(text,attr1=val1,attr2=val2):
64 #create and open tag 'sub_tag'
65 with xml.sub_tag(text,attr3=val3):
66 #create tag which are not valid python identificator
67 with xml('one-more-sub-tag',attr7=val37):
68 xml << "Some textual data"
69 #here tag 'one-more-sub-tag' are closed
70 #Tags without children can be created using `<<` operator
72 xml << ('message',"python rocks!"[:i])
73 #create 15 child tag like <message> python r</message>
75 node = ~x # get etree.ElementTree object
77 unicode_xml_data = unicode(x)