deeper pass on xmlrpclib vs xmlrpc.client as well as configparser
[sfa.git] / xmlbuilder-0.9 / xmlbuilder / docs / long_descr.rst
1 Example of usage:\r
2 -----------------\r
3 \r
4 \r
5 from __future__ import with_statement\r
6 from xmlbuilder import XMLBuilder\r
7 x = XMLBuilder(format=True)\r
8 with x.root(a = 1):\r
9     with x.data:\r
10         [x << ('node',{'val':i}) for i in range(10)]\r
11 \r
12 print str(x)\r
13 \r
14 will print\r
15 \r
16 <root a="1">\r
17     <data>\r
18         <node val="0" />\r
19         <node val="1" />\r
20         <node val="2" />\r
21         <node val="3" />\r
22         <node val="4" />\r
23         <node val="5" />\r
24         <node val="6" />\r
25         <node val="7" />\r
26         <node val="8" />\r
27         <node val="9" />\r
28     </data>\r
29 </root>\r
30 \r
31 Mercurial repo:http://hg.assembla.com/MyPackages/\r
32 \r
33 Documentations\r
34 --------------\r
35 `XMLBuilder` is simple library build on top of `ElementTree.TreeBuilder` to\r
36 simplify xml files creation as much as possible. Althow it can produce\r
37 structured result with identated child tags. `XMLBuilder` use python `with`\r
38 statement to define xml tag levels and `<<` operator for simple cases -\r
39 text and tag without childs.\r
40 \r
41 First we need to create xmlbuilder\r
42 \r
43     from xmlbuilder import XMLBuilder\r
44     # params - encoding = 'utf8',\r
45     # builder = None, - ElementTree.TreeBuilder \r
46     # tab_level = None, - current tab l;evel - for formatted output only\r
47     # format = False, - create formatted output\r
48     # tab_step = " " * 4 - indentation step\r
49     xml = XMLBuilder()\r
50 \r
51 \r
52 Use `with` statement to make document structure\r
53     #create and open tag 'root_tag' with text 'text' and attributes\r
54     with xml.root_tag(text,attr1=val1,attr2=val2):\r
55         #create and open tag 'sub_tag'\r
56         with xml.sub_tag(text,attr3=val3):\r
57             #create tag which are not valid python identificator\r
58             with xml('one-more-sub-tag',attr7=val37):\r
59                 xml << "Some textual data"\r
60             #here tag 'one-more-sub-tag' are closed\r
61                         #Tags without children can be created using `<<` operator\r
62             for val in range(15):\r
63                 xml << ('message',"python rocks!"[:i])\r
64             #create 15 child tag like <message> python r</message>\r
65     #all tags closed\r
66     node = ~x # get etree.ElementTree object\r
67     xml_data = str(x)\r
68     unicode_xml_data = unicode(x)\r