#xml_weather.py # #Copyright Jay Summet # #Example parsing of NOAA weather XML data, both from a file #and directly from the WWW. import xml.etree.ElementTree as etree import urllib.request #Sample XML weather data files: #http://www.weather.gov/xml/current_obs #atlanta Fulton/Brown airport: #http://www.weather.gov/data/current_obs/KFTY.xml def weatherDemo(): #From a file: filename = "KFTY.xml" tree = etree.parse(filename) #From the web: #response = urllib.request.urlopen("http://www.weather.gov/data/current_obs/KFTY.xml") #tree = etree.parse(response) root = tree.getroot() print(root) for item in root: print(item.tag, ":", item.text) print(root.attrib['version'] ) weatherDemo()