Getting an xpath from an etree.DocumentInvalid exception
19 Jul
2016
19 Jul
'16
9:52 p.m.
Hello, I'm using lxml to build a validation website for an XML schema. When a file does not meet a schema, I would like to give users the xpath or a snippet of their input XML to show the error. Therefore, I'm trying to work out how to get an xpath to a problem XML element/attribute - i.e. when a etree.DocumentInvalid exception is raised. The approach that I have thought about is to build a mapping of all xpaths to line numbers, and then get find the nearest line to DocumentInvalid.error_log.last_error.line However, a) this feels a bit hacky and b) this won't work for minified files. Is there a better way? Many thanks, and look forward to hearing any thoughts! Dale
2831
Age (days ago)
2831
Last active (days ago)
0 comments
1 participants
participants (1)
-
Dale Potter