diff --git a/src/rougail/xmlreflector.py b/src/rougail/xmlreflector.py
index d6352c712..37fbd16f3 100644
--- a/src/rougail/xmlreflector.py
+++ b/src/rougail/xmlreflector.py
@@ -3,7 +3,7 @@ from os.path import join, isfile, basename, isdir
from os import listdir
#from io import BytesIO
-from lxml.etree import DTD, parse, tostring # , XMLParser
+from lxml.etree import DTD, parse, tostring, XMLSyntaxError
from .i18n import _
from .error import DictConsistencyError
@@ -34,10 +34,12 @@ class XMLReflector(object):
:returns: the root element tree object
"""
- # document = parse(BytesIO(xmlfile), XMLParser(remove_blank_text=True))
- document = parse(xmlfile)
+ try:
+ document = parse(xmlfile)
+ except XMLSyntaxError as err:
+ raise DictConsistencyError(_(f'{xmlfile} is not an XML file: {err}'), 52)
if not self.dtd.validate(document):
- raise DictConsistencyError(_(f'"{xmlfile}" not a valid xml file: {self.dtd.error_log.filter_from_errors()[0]}'), 43)
+ raise DictConsistencyError(_(f'"{xmlfile}" not a valid XML file: {self.dtd.error_log.filter_from_errors()[0]}'), 43)
return document.getroot()
def load_xml_from_folders(self, xmlfolders):
diff --git a/tests/dictionaries/80invalid_dtd/00_base.xml b/tests/dictionaries/80invalid_dtd/00_base.xml
new file mode 100644
index 000000000..5377be4c9
--- /dev/null
+++ b/tests/dictionaries/80invalid_dtd/00_base.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/tests/dictionaries/80invalid_dtd/__init__.py b/tests/dictionaries/80invalid_dtd/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/dictionaries/80invalid_dtd/errno_43 b/tests/dictionaries/80invalid_dtd/errno_43
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/dictionaries/80invalid_xml/00_base.xml b/tests/dictionaries/80invalid_xml/00_base.xml
new file mode 100644
index 000000000..7234125c9
--- /dev/null
+++ b/tests/dictionaries/80invalid_xml/00_base.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/tests/dictionaries/80invalid_xml/__init__.py b/tests/dictionaries/80invalid_xml/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/dictionaries/80invalid_xml/errno_52 b/tests/dictionaries/80invalid_xml/errno_52
new file mode 100644
index 000000000..e69de29bb