-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
35 lines (31 loc) · 966 Bytes
/
examples.py
File metadata and controls
35 lines (31 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
from pprint import pprint
from lxml2json import lxml_to_dict
from lxml import etree as ET
from lxmlwrapper import E
elem = E('resp', status=1)
elem.append( E('lalla').add('e') )
elem.append( E('lalla').add('f') )
elem.append( E('lalla').add( E('chuj') ) )
elem.append( E('lalla', hidden=0,text1='a').add('g') )
elem.append( E('lalla3', hidden=0).add('g') )
print ET.tostring(elem,pretty_print=True)
#<resp status="1">
# <lalla>e</lalla>
# <lalla>f</lalla>
# <lalla>
# <chuj/>
# </lalla>
# <lalla hidden="0" text1="a">g</lalla>
# <lalla3 hidden="0">g</lalla3>
#</resp>
pprint( lxml_to_dict(elem), width=40 )
#{'resp': {'lalla': [{'text': 'e'},
# {'text': 'f'},
# {'chuj': [{}]},
# {'hidden': '0',
# 'text': 'g',
# 'text1': 'a'}],
# 'lalla3': [{'hidden': '0',
# 'text': 'g'}],
# 'status': '1'}}