# # Another way to parse XML # # Matt Bishop, MHI 289I, Fall 2024 # import xml.etree.ElementTree as ET import sys # # function to pause output # def pauseoutput(): try: toss = input(">> ") except Exception: sys.exit(0) # # load the XML into memory # try: fptr = open("sample1.xml", "r") except Exception as msg: print(msg) sys.exit(1) xmltmp = fptr.read() xmltree = ET.fromstring(xmltmp) # # print the tree as an object # print(xmltree) pauseoutput() # # now print the whole tree # print("Here's the actual XML tree itself") for node in xmltree.iter(): if node.text: print(node.tag, node.attrib, " *** value is '"+node.text+"'") else: print(node.tag, node.attrib, " *** no value")