Looking for python Answers? Try Ask4KnowledgeBase
Looking for python Keywords? Try Ask4Keywords

Python Language Opening and reading using an ElementTree


Import the ElementTree object, open the relevant .xml file and get the root tag:

import xml.etree.ElementTree as ET
tree = ET.parse("yourXMLfile.xml")
root = tree.getroot()

There are a few ways to search through the tree. First is by iteration:

for child in root:
    print(child.tag, child.attrib)

Otherwise you can reference specific locations like a list:


To search for specific tags by name, use the .find or .findall: