Python Programming - Standard Libraries - Discussion

Discussion Forum : Standard Libraries - General Questions (Q.No. 87)
87.
How can you use the xml.etree.ElementTree module in Python to parse an XML file?
xml.etree.ElementTree.parse(file_path)
xml.etree.ElementTree.load(file_path)
xml.etree.ElementTree.read(file_path)
xml.etree.ElementTree.fromfile(file_path)
Answer: Option
Explanation:
import xml.etree.ElementTree as ET

# Example usage of xml.etree.ElementTree module for parsing an XML file
tree = ET.parse('data.xml')
root = tree.getroot()
for element in root:
    print(element.tag, element.attrib)
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.