I am trying to parse multiple xml files for a specific tag, and if file contains that tag, then extract the text associated with tag.
I am learning Python on and off for over a year, and this is my first attempt at dealing with xml.
here is my code where changeM is the tag of interest:
import os
import glob
import xml.etree.ElementTree as ET
import pandas as pd
read_files = glob.glob(os.path.join(path, '*.xml'))
for file in read_files:
new_tree = ET.parse(file)
root = new_tree.getroot()
changes=[]
for elm in root.findall('.//para[@changeM="1"]'):
changes.append(elm.text)
The list named 'changes' is blank. Alternatively if I discard the list in the above code, I sub a print statement, then it picks up one of the text but prints the same text match repeatedly.