mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
Validate CAP against the spec
This gives us some extra confidence that there aren’t any problems with the data we’re getting from the other service. It doesn’t address any specific problems we’ve seen, rather it seems like a sensible precaution to take.
This commit is contained in:
19
app/xml_schemas/__init__.py
Normal file
19
app/xml_schemas/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from lxml import etree
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def validate_xml(document, schema_file_name):
|
||||
|
||||
path = Path(__file__).resolve().parent / schema_file_name
|
||||
contents = path.read_text()
|
||||
|
||||
schema_root = etree.XML(contents.encode('utf-8'))
|
||||
schema = etree.XMLSchema(schema_root)
|
||||
parser = etree.XMLParser(schema=schema)
|
||||
|
||||
try:
|
||||
etree.fromstring(document, parser)
|
||||
except etree.XMLSyntaxError:
|
||||
return False
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user