import xml.etree.ElementTree as ET
data = '''
<person>
<name>Chunk</name>
<pone type="intl">+1 734 303 4456</pone>
<email hide="yes"/>
</person>
'''
print(data)
tree = ET.fromstring(data)
print(type(tree))
print("Name :", tree.find("name").text)
print("Attr :", tree.find("email").get("hide"))
print()
data = '''
<stuff>
<users>
<user x="2">
<id>001</id>
<name>Chuck</name>
</user>
<user x="7">
<id>009</id>
<name>Brent</name>
</user>
</users>
</stuff>
'''
print(data)
tree = ET.fromstring(data)
print(type(tree))
_users = tree.findall("users/user")
print("User count :", len(_users))
print(type(_users))
print()
for _user in _users :
print(type(_user))
print("Name :", _user.find("name").text)
print("Id :", _user.find("id").text)
print("Attribute X :", _user.get("x"))
print()
>>> exec(open("xml01.py").read())
<person>
<name>Chunk</name>
<pone type="intl">+1 734 303 4456</pone>
<email hide="yes"/>
</person>
<class 'xml.etree.ElementTree.Element'>
Name : Chunk
Attr : yes
<stuff>
<users>
<user x="2">
<id>001</id>
<name>Chuck</name>
</user>
<user x="7">
<id>009</id>
<name>Brent</name>
</user>
</users>
</stuff>
<class 'xml.etree.ElementTree.Element'>
User count : 2
<class 'list'>
<class 'xml.etree.ElementTree.Element'>
Name : Chuck
Id : 001
Attribute X : 2
<class 'xml.etree.ElementTree.Element'>
Name : Brent
Id : 009
Attribute X : 7
xml 파싱 1
|
2019.09.03 15:14:25
|
2019.09.03 15:14:39
|
565
|
Aiden
Total of Attached file
0.00 Bytes of 0 files
2019.09.24
2019.09.16
2019.09.14
2019.09.03
2019.09.03
2019.08.30
2019.08.30
2019.08.30
2019.08.29