I am using libxml2 python for parsing my xml and validate it against an xsd file.
I was unable to find out the line number of the error in xml file when i get an schema validation error.
Is there a way?
For better understanding i have pasted my code below:
ctxt = libxml2.schemaNewParserCtxt("xsd1.xsd")
schema = ctxt.schemaParse()
del ctxt
validationCtxt = schema.schemaNewValidCtxt()
doc = libxml2.parseFile("myxml.xml")
iErrA1 = validationCtxt.schemaValidateDoc(doc)
#get the line number if there is error
Update:
I tried libxml2.lineNumbersDefault(1), this probably enables the library to collect line numbers. Then i register a callback through validationCtxt.setValidityErrorHandler(ErrorHandler, ErrorHandler). I get the msg part but no line number is present. More info: I had seen a line number member in xmlError, but its unclear to me as to how I will get this xmlError type object back when there is an error. Also there is a global function lastError which returns an xmlError type object, but it always returns 'none' although there is an error