Stuck on something and don't see it in the documentation. I'm trying to query very large XML files based on the text value of , etc. and one of the values I would love to get when querying is the complete absolute path, including indexing information.
import xml.etree.ElementTree as ET
xmlfile = *pathtoFile*
tree = ET.parse(xmlfile)
root = tree.getroot()
for elm in root.findall("./sequence/media/video/track/clipitem/file/name[.='Graphic']../../name"):
CurrentClip = (elm.text)
Graphics_Name_List.append(CurrentClip)
for elm in root.findall("./sequence/media/video/track/clipitem/file/name[.='Graphic']../../start"):
CurrentClip = (elm.text)
Graphics_Start_List.append(CurrentClip)
The above code will append of all graphics to a list named "Graphics_Name_List", and the of all graphics to a list named "Graphics_Start_List", by using (elm.text)
What I'm really hoping to find is a way to include the entire absolute path to these elements that I've queried. I found 2 interesting answers elsewhere on StackOverflow, but they do not include indexing.
Capture all XML element paths using xml.etree.ElementTree
Get Xpath dynamically using ElementTree getpath()
Both of those functions return Xpath like this:
./sequence/media/video/track/clipitem/filter/effect/parameter/name
But what I really require is an Xpath like this, with indexing:
./sequence[0]/media[0]/video[0]/track[3]/clipitem[56]/filter[0]/effect[0]/parameter[0]/name[0]
What I'm really trying to do is pull which Track/Clipitem it appears in (Track 3? Track 5?), but I'm currently finding that to be tough.
So far I believe I'm only using features from xml.etree.ElementTree... I know there's a feature in lxml that can do this, but I also don't know how to mix modules and became a little confused when passing an element value that had been parsed in ET.parse(xmlfile) into etree.Xpath(elm)... is that even possible?