2012-01-16 32 views
2

我正在關注的lxml validation documentation構建驗證對數學ML 3.0架構一個給定的XML字符串的類。下面是類:lxml/MathML XML Schema - 如何解決「內容模型不確定性」。錯誤?

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) 

實例化它產生如下:

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

我該如何解決這個問題?

+0

架構是〜1900線長,很遺憾。 well_formed_xml_string = <數學的xmlns = 「http://www.w3.org/1998/Math/MathML」> – MikeRand 2012-01-17 21:16:05

+0

well_formed_xml_string ='<數學的xmlns = 「http://www.w3.org/1998/Math/MathML」 >' – MikeRand 2012-01-17 21:24:48

回答

6

HMM的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或其他東西和其他東西是其他名稱空間(##其他)或不在名稱空間(## local)中的東西。

我無法瞭解哪些選項是不確定性的,但你可以嘗試簡化的東西,例如,如果你實際上並不需要取消命名空間的註釋去掉##國貨條款。

如果你得到它的工作(或者如果沒有)你能ping我在[email protected]名單,我會修復架構,如果它需要修復(或至少記錄lxml需要本地修改)(我不明白這個論壇上,剛剛拿起MATHML一個谷歌的警告:-)


更新

至於MathML3 2nd edition更新的一部分我在XSD版本重寫的內容模型以便它被libxml接受。舊的模式沒有錯,但對用戶沒有幫助,所以改變它似乎更好。

+0

已發送電子郵件至[email protected] ...解決方案工作。 – MikeRand 2012-01-22 18:17:18

+1

我在PHP解析MATHML(V3)XSD時...註釋掉固定它的##本地線路有同樣的問題,因爲@MikeRand。謝謝! – Justin 2012-12-06 19:24:55

+1

@Justin在這個問題上搜索這個似乎是libxml中已經打開了一段時間的bug。 https://bugzilla.gnome.org/show_bug.cgi?id=573483 – 2012-12-06 22:18:49

相關問題