I have a function that reads certain tags out of an XML file. I am trying to make it so that if the tags don’t exist (the variable to tag assignment fails) that an exception is called and the file is moved to a different directory and the next file is read in.
Here is my function:
def iterateOverXml():
localPath = "C:\local"
remotePath = "C:\outbox"
errorPath = "C:\Error"
xmlFiles = glob.glob1(localPath,"*.xml")
for file in xmlFiles:
print file
a = os.path.join(localPath,file)
element = etree.parse(a)
try:
data= element.xpath('//Foobar/Data/node()')
parsedData = [{field.tag: field.text for field in data} for action in data]
xmlType = parsedData[0]['FormType']
except:
shutil.move(os.path.join(localPath,file),errorPath)
if xmlType == 'record':
parseTitle(element)
parseTracks(element)
parseArtist(element)
shutil.move(os.path.join(localPath,file),remotePath)
How can I make it so if the exception is met it both moves the file the current iteration is stopped and the next file is called?
Just use
continue: