import xml.etree.ElementTree as ET
root = ET.parse('jobs.xml').getroot() #root: jobs
for job in root.findall('job'):
print(job.get('category')) #attribute: category
for elements in job:
#elements: location, conditions, payperhour
Note - the windows above contain an XML file (jobs.xml) and a Python script that can parse this jobs.xml file.
Ensure both files are saved in the same
XML stands for eXtensible Markup Language.
XML documents are formed as 'element trees' that branch out from the root element (in this case the root element is jobs
). Note: elements can have sub elements, which can have more sub elements, etc.
Elements can have text
Elements can have attributes
RSS (Real Simple Syndication) feeds are implementations
of XML, and are generally used for sharing live content (e.g. news headlines, weather updates, etc). RSS files are written in XML