[lxml-dev] Schema validation - no file position

Hi, I'm trying to validate a document using XmlSchema. It works but the exception received (etree.XMLSyntaxError) has no information about file position- exc.position is (0,0). Is this correct behaviour?

Hi, Krzysztof Jakubczyk, 18.11.2010 11:15:
I'm trying to validate a document using XmlSchema. It works but the exception received (etree.XMLSyntaxError) has no information about file position- exc.position is (0,0). Is this correct behaviour?
I wonder why you get an "XMLSyntaxError" in the first place. This means that there's an error while parsing your document. Could you show us the code that you use for parsing and validation? Stefan

On 2010-11-25 10:48, Stefan Behnel wrote:
Hi,
Krzysztof Jakubczyk, 18.11.2010 11:15:
I'm trying to validate a document using XmlSchema. It works but the exception received (etree.XMLSyntaxError) has no information about file position- exc.position is (0,0). Is this correct behaviour?
I wonder why you get an "XMLSyntaxError" in the first place. This means that there's an error while parsing your document.
Could you show us the code that you use for parsing and validation?
Stefan Hmm... I get the error because the document I validate is invalid - it doesn't match the Xml Schema. This behavior is correct. My problem is that the error doesn't contain information about position of the error - it's hard to find source of the error in a big file.
my code is the following: def validate(schemaContent, dataStream): schema = etree.XMLSchema(etree.fromstring(schemaContent)) for event, elem in etree.iterparse(dataStream, schema=schema): elem.clear() while elem.getprevious() is not None: if not elem.getparent() is None: del elem.getparent()[0] regards, kj

Krzysztof Jakubczyk, 25.11.2010 11:00:
On 2010-11-25 10:48, Stefan Behnel wrote:
Krzysztof Jakubczyk, 18.11.2010 11:15:
I'm trying to validate a document using XmlSchema. It works but the exception received (etree.XMLSyntaxError) has no information about file position- exc.position is (0,0). Is this correct behaviour?
I wonder why you get an "XMLSyntaxError" in the first place. This means that there's an error while parsing your document.
Could you show us the code that you use for parsing and validation?
I get the error because the document I validate is invalid - it doesn't match the Xml Schema. This behavior is correct. My problem is that the error doesn't contain information about position of the error - it's hard to find source of the error in a big file.
my code is the following:
def validate(schemaContent, dataStream): schema = etree.XMLSchema(etree.fromstring(schemaContent)) for event, elem in etree.iterparse(dataStream, schema=schema):
Now, this reveals two important hints that you didn't provide in your original post: you are validating at parse time, and you are using iterparse(). For me, that totally changes the place in the code to look at. I'll see if I can come up with something. Stefan
participants (2)
-
Krzysztof Jakubczyk
-
Stefan Behnel