I am currently learning python to automate a few things in my job. I need to retrieve a tag value from multiple xml files in a directory. The directory has many subfolders too.
I tried the following code, and understood what is missing. But I am not able to fix this. Here is my code:
from xml.dom.minidom import parse, parseString
import os
def jarv(dir):
for r,d,f in os.walk(dir):
for files in f:
if files.endswith(".xml"):
print files
dom=parse(files)
name = dom.getElementsByTagName('rev')
print name[0].firstChild.nodeValue
jarv("/path)
I understand that while executing the dom=parse(files) line, it has got the filename without the path. So it says no such files/directory.
I don't know how to fix this.
print. It's really useful to debug. Before the linedom=parse(files)add the lineprint filesand you will see what it contains