Assume you have the following XML document with a syntax error (missing close tag </title>
):
<book xmlns="http://docbook.org/ns/docbook" version="5.1">
<title><!--</title>-->
<index/>
</book>
dbxincluder tests/cases/wrong.xml
Traceback (most recent call last):
File "/local/doc/dbxincluder/.env/bin/dbxincluder", line 9, in <module>
load_entry_point('dbxincluder==0.1.0', 'console_scripts', 'dbxincluder')()
File "/local/doc/dbxincluder/src/dbxincluder/__init__.py", line 186, in main
sys.stdout.write(process_xml(inputxml, base_url, path))
File "/local/doc/dbxincluder/src/dbxincluder/__init__.py", line 127, in process_xml
tree = lxml.etree.fromstring(xml, base_url=base_url)
File "lxml.etree.pyx", line 3103, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70569)
File "parser.pxi", line 1828, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106403)
File "parser.pxi", line 1716, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:105194)
File "parser.pxi", line 1086, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:99876)
File "parser.pxi", line 580, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:94350)
File "parser.pxi", line 690, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:95786)
File "parser.pxi", line 620, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:94853)
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: title line 3 and book, line 5, column 8
You want to catch this exception. ๐