-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml_hardcoded.py
More file actions
39 lines (35 loc) · 1010 Bytes
/
xml_hardcoded.py
File metadata and controls
39 lines (35 loc) · 1010 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
36
37
38
39
import xml.etree.ElementTree as ET
data = '''
<person>
<users>
<user x='1'>
<name>Chuck</name>
<phone type="intl">
+1 734 303 4456
</phone>
<email hide="yes" />
</user>
<user x='2'>
<name>Ruben</name>
<phone type="intl">
+1 9744706991
</phone>
<email hide="no" />
</user>
</users>
</person>'''
tree = ET.fromstring(data)
# print('# DEBUG: ',tree)
# print('Name:', tree.find('name').text)
# print('Phone:', tree.find('phone').text.strip())
# print('Phone type' , tree.find('phone').get('type'))
# print('Attr:', tree.find('email').get('hide'))
people = tree.findall('user')
people2 = tree.findall('users/user')
print('# DEBUG: ',len(people))
print('# DEBUG: ',len(people2))
for dude in people2:
print('Name: ',dude.find('name').text)
print('Phone Num: ',dude.find('phone').text)
print('Email hide: ',dude.find('email').get('hide'))
print('Attribute: ',dude.get('x'))