lxml/mathmlxmlschema如何修复“内容模型不是确定性的”错误?

2024-06-09 00:01:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我跟随lxml validation documentation构建一个类,该类根据MathML3.0模式验证给定的XML字符串。课程如下:

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)

实例化它会产生以下结果:

^{pr2}$

我怎么解决这个问题?在


Tags: topathselfstringdocdefxmlfile
1条回答
网友
1楼 · 发布于 2024-06-09 00:01:48

嗯,我尝试的xsd验证器没有说它是不确定的(但我没有使用lxml) 相关代码是

  <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>

也就是说,注释xml可以接受mathml或其他内容,而其他内容是其他名称空间(##other)中的内容,或者不在名称空间(##local)中。在

我看不出其中哪些选项是不确定的,但是如果您实际上不需要非名称空间的注释,可以尝试简化一些事情,例如删除##local子句。在

如果你能让它正常工作(如果不行),你能告诉我www-math@w3.org如果需要修改的话,我会修复它(或者至少记录lxml需要本地修改)(我不关注这个论坛,只是在google上找到了一个警告)数学:-)在


更新

作为MathML3 2nd edition更新的一部分,我在XSD版本中重写了内容模型,以便libxml接受它。旧的模式没有错,但这对用户没有帮助,所以最好是更改它。在

相关问题 更多 >