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
However, a) this feels a bit hacky and b) this won't work for minified
Is there a better way?
Many thanks, and look forward to hearing any thoughts!