I am trying to open a directory containing a series of XML in one specific directory.
In the following code, I repeat each XML document, and I set some “if statements” to read the text in XML, search for keywords and replace them, and then write a new file to a new location. When running the script:
I get the following error:Traceback info:
File "Z:\ESRI\Python\Test Scripts\ElementTree6.py", line 62, in <module>
if "%begdate%" in element.text:
...
Error Information:
argument of type 'NoneType' is not iterable
I hardcoded the directory for one specific XML, and when I run the if statements, they work fine.
This is when I try to set up an iteration using an XML series in which I encountered an error.
I looked through this site to find out if I can solve the final solution, but all the problems are either different from mine, or I don’t quite understand the work.
I used multiple print lines to check the output.
Everything works fine until I get to the if statement, and then an error occurs.
folderPath = r"Z:\data"
for filename in glob.glob(os.path.join(folderPath, "*.xml")):
fullpath = os.path.join(folderPath, filename)
if os.path.isfile(fullpath):
basename, filename2 = os.path.split(fullpath)
root = ElementTree(file=r"Z:\data\\" + filename2)
iter = root.getiterator()
for element in iter:
if "%begdate%" in element.text:
BEGDATE = element.text.replace("%begdate%", BEGDATEPARAM)
element.text = BEGDATE
source
share