libXML now returnes info why XML is not valid

This commit is contained in:
2023-06-05 14:25:25 +02:00
parent 89517a6821
commit 1ddf06a830

View File

@@ -77,10 +77,12 @@ def xsd(source: str, xsd: str) -> bool:
document_input = BytesIO(source.encode("utf-8"))
xml = etree.parse(document_input).getroot()
if xml_schema.validate(xml):
return "XML is valid."
else:
return "XML is NOT valid."
try:
xml_schema.assertValid(xml)
return "XML is valid"
except etree.DocumentInvalid as e:
return str(e)
def xslt(source: str, xslt: str) -> str: