6 hooks to check XML syntax 9 pretxncommit.check_xml = python:/path-to/hooks:check_xml 13 from xml.etree
import ElementTree
as ET
17 SEPARATOR =
'%s\n' % (
'-' * 79)
20 def xml_parser(content):
22 tree = ET.fromstring(content)
23 except ET.ParseError
as err:
24 line_number, column = err.position
25 line = content.splitlines()[line_number - 2]
26 caret =
'{:=>{}}'.format(
'^', column)
27 err.msg =
'{}\n{}\n{}'.format(err, line, caret)
36 if f.path.lower().endswith((
'.xml',
'.xsd')):
41 except ET.ParseError
as err:
43 common.error(
'XML parsing error in ' + f.path +
' :\n ' + err.msg +
'\n.')
50 'check_xml': check_xml,