-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebServices.py
56 lines (53 loc) · 1.31 KB
/
WebServices.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# import xml.etree.ElementTree as ET
# data = '''<person>
# <name>Chuck</name>
# <phone type="int1">
# + 1 734 303 4456
# </phone>
# <email hide="yes"/>
# </person>'''
#
# tree = ET.fromstring(data)
# print('Name:',tree.find('name').text)
# print('Attr:',tree.find('email').get('hide'))
# import xml.etree.ElementTree as ET
# input = '''<stuff>
# <users>
# <user x="2">
# <id>001</id>
# <name>Chuck</name>
# </user>
# <user x="7">
# <id>009</id>
# <name>Brent</name>
# </user>
# </users>
# </stuff>'''
#
# stuff = ET.fromstring(input)
# lst = stuff.findall('users/user')
# print('User count:', len(lst))
# for item in lst:
# print('Name', item.find('name').text)
# print('Id', item.find('id').text)
# print('Attribute', item.get("x"))
import xml.etree.ElementTree as ET
input = '''<stuff>
<users>
<user x="2">
<id>001</id>
<name>Brent</name>
</user>
<user x="7">
<id>009</id>
<name>Brent</name>
</user>
</users>
</stuff>'''
stuff = ET.fromstring(input)
lst = stuff.findall('users/user')
print('User count:', len(lst))
for item in lst:
print('Name', item.find('name').text)
print('Id', item.find('id').text)
print('Attribute',item.get("x"))