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