Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
19 lines (13 loc) · 534 Bytes

File metadata and controls

19 lines (13 loc) · 534 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# parse_xml.py
from xml.etree.ElementTree import ElementTree
def parse_xml(xml_file):
tree = ElementTree(file=xml_file)
root_element = tree.getroot()
print(f"The root element's tag is '{root_element.tag}'")
for child_element in root_element:
print(f'{child_element.tag=}, {child_element.text=}')
if child_element.tag == 'note':
for note_element in child_element:
print(f'{note_element.tag=}, {note_element.text=}')
if __name__ == '__main__':
parse_xml('note.xml')
Morty Proxy This is a proxified and sanitized view of the page, visit original site.