# # Example of XML functions and methods in Python # # Matt Bishop, MHI 289I, Fall 2021 # 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 # fptr = open("demo.xml", "r") xmltree = ET.parse(fptr) xmltreeroot = xmltree.getroot() # # 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") pauseoutput()