I'm following the lxml validation documentation to build a class that validates a given XML string against the Math ML 3.0 schema. Here's the class:
class XMLSchema(object):
def __init__(self, path_to_xsd_file):
with open(path_to_xsd_file) as f:
xmlschema_doc = etree.parse(f)
self.xmlschema = etree.XMLSchema(xmlschema_doc)
def validate(self, well_formed_xml_string):
"""Validates a well-formed XML string against an XML schema.
Returns True if xml_string is valid, False if not.
"""
xml = etree.parse(StringIO(well_formed_xml_string))
return self.xmlschema.validate(xml)
Instantiating it produces the following:
>>> x = XMLSchema('mathml3.xsd')
Traceback (most recent call last):
...
lxml.etree.XMLSchemaParseError: complex type
'annotation-xml.model': The content model is not determinist., line 42
How do I fix this?