like xpathfirstwe could run basic pattern matching on the file' textthough this tends to be inaccurate if the text is unpredictable where applicablethe re module we met earlier does the job--its match method looks for match at the start of stringsearch scans ahead for matchand the findall method used here locates all places where the pattern matches in the string (the result comes back as list of matched substrings corresponding to parenthesized pattern groupsor tuples of such for multiple groups)file patternparse py import re text open('mybooks xml'read(found re findall('*)'textfor title in foundprint(titlesecondto be more robustwe could perform complete xml parsing with the standard library' dom parsing support dom parses xml text into tree of objects and provides an interface for navigating the tree to extract tag attributes and valuesthe interface is formal specificationindependent of pythonfile domparse py from xml dom minidom import parsenode xmltree parse('mybooks xml'for node in xmltree getelementsbytagname('title')for node in node childnodesif node nodetype =node text_nodeprint(node dataas third optionpython' standard library supports sax parsing for xml under the sax modela class' methods receive callbacks as parse progresses and use state information to keep track of where they are in the document and collect its datafile saxparse py import xml sax handler class bookhandler(xml sax handler contenthandler)def __init__(self)self intitle false def startelement(selfnameattributes)if name ='title'self intitle true def characters(selfdata)if self intitleprint(datadef endelement(selfname)if name ='title'self intitle false import xml sax parser xml sax make_parser(handler bookhandler( unicode and byte strings