If I try to parse a broken XML the exception shows the line number. Is there a way to show the XML context?
I want to see the xml tags before and after the broken part.
Example:
import xml.etree.ElementTree as ET
tree = ET.fromstring('<a><b></a>')
Exception:
Traceback (most recent call last):
File "tmp/foo.py", line 2, in <module>
tree = ET.fromstring('<a><b></a>')
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1300, in XML
parser.feed(text)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: mismatched tag: line 1, column 8
Something like this would be nice:
ParseError:
<a><b></a>
=====^