I have a function like this:
import lxml.etree as ET def do_things(filename, schema=None): """ Do things with XML file, and use schema for validation at parse time Params: filename: file path for XML file schema: schema for validation returns: things """ iter_file = ET.iterparse(filename, schema=schema) while True: try: event, element = iter_file.next() #do things except StopIteration: break except ET.XMLSyntaxError as e: print(e.message) return #things
I want to iterate over my XML file and use a .xsd schema file for validation at parse time. When a error XMLSyntaxError comes up, I want to be able to continue iterating. (In the end I want to be able to summarise where and how many syntax errors have occured). However, on my current solution the .next() method returns me always the same element where the first syntax error occurred.
No comments:
Post a Comment