test invalid xml
This commit is contained in:
parent
81d30612e8
commit
f8959ef16f
|
@ -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):
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<services>
|
||||
<unknown>
|
||||
</unknown>
|
||||
</services>
|
||||
</rougail>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<services/>
|
||||
</services>
|
||||
</rougail>
|
Loading…
Reference in New Issue