Mik*_*and 2 python xsd lxml mathml
我正在遵循lxml验证文档来构建一个类,该类根据Math ML 3.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)
Run Code Online (Sandbox Code Playgroud)
实例化它会产生以下结果:
>>> 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
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
嗯我试过的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>
Run Code Online (Sandbox Code Playgroud)
应该说annotation-xml可以使用mathml或其他东西,其他东西是其他命名空间(## other)中的东西,或者不是命名空间中的东西(## local).
我看不出哪些选项是非确定性的,但您可以尝试简化一些事情,例如,如果您实际上不需要非命名空间注释,请删除## local子句.
如果你让它工作(或者如果没有)你可以在www-math@w3.org列表上ping我,如果需要修复我会修复架构(或至少记录lxml需要本地修改)(我不要不要关注这个论坛,只是拿了一个关于mathml的谷歌警报:-)
作为MathML3第二版更新的一部分,我在XSD版本中重写了内容模型,以便libxml接受它.旧模式没有错,但这对用户没有帮助,因此更改它似乎更好.
| 归档时间: |
|
| 查看次数: |
2582 次 |
| 最近记录: |