2

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?

4

1 回答 1

6

hmm the xsd validators I tried didn't say it was non deterministic (but I didn't use lxml) the relevant code is

  <xs:complexType name="annotation-xml.model">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
         <xs:group ref="m:MathExpression"/>
         <xs:group ref="m:anyElement"/>
      </xs:choice>
   </xs:complexType>
   <xs:group name="anyElement">
      <xs:choice>
         <xs:any namespace="##other" processContents="skip"/>
         <xs:any namespace="##local" processContents="skip"/>
      </xs:choice>
   </xs:group>

which should say that annotation-xml can take mathml or other stuff and other stuff is things in other namespaces (##other) or not in a namespace (##local).

I can't see which of those choices are non deterministic, but you could try simplifying things eg remove the ##local clause if you don't actually need un-namespaced annotations.

If you get it working (or if not) could you ping me on the www-math@w3.org list and I'll fix the schema if it needs fixing (or at least record that lxml requires a local modification) (I don't follow this forum, just picked up a google alert on mathml:-)


Update

As part of the update for MathML3 2nd edition I have rewritten the content model in the XSD version so that it is accepted by libxml. The old schema was not at fault, but that does not help the user, so it seemed better to change it.

于 2012-01-19T11:59:53.240 回答