Files
notifications-api/app/xml_schemas/__init__.py

16 lines
456 B
Python
Raw Normal View History

from pathlib import Path
2022-08-18 17:52:44 +00:00
from defusedxml.lxml import fromstring
# there is no equivalent in defusedxml to validate a schema
from lxml.etree import XMLSchema # nosec B410
2021-03-10 13:55:06 +00:00
def validate_xml(document, schema_file_name):
path = Path(__file__).resolve().parent / schema_file_name
contents = path.read_text()
2022-08-18 17:52:44 +00:00
schema_root = fromstring(contents.encode('utf-8'))
schema = XMLSchema(schema_root)
return schema.validate(fromstring(document))