test invalid xml
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user