QXmlSchemaValidator在包含substitutionGroups時未驗證我的XML。在線工具(http://www.utilities-online.info/xsdvalidation/,http://www.freeformatter.com/xml-validator-xsd.html)根據XSD驗證XML,XSD和XML。QXmlSchemaValidator(Qt 4.8)是否支持XML模式(XSD)屬性「substitutionGroup」
錯誤:
Error XSDError in file: (XML), at line 44, column 14: Element image_id is not defined in this scope.
相關代碼,XSD:
<xs:element name="image_ids" abstract="true"/>
<xs:element name="image_id" type="xs:nonNegativeInteger" substitutionGroup="image_ids"/>
<xs:element name="image_queue_id" type="xs:nonNegativeInteger" substitutionGroup="image_ids"/>
<xs:element name="image_slot">
<xs:complexType>
<xs:all>
<xs:element ref="image_ids" maxOccurs="1"/>
<xs:element ref="caption" minOccurs="0" maxOccurs="1"/>
</xs:all>
<xs:attributeGroup ref="position"/>
</xs:complexType>
</xs:element>
相關代碼,XML:
<image_slot x="7" y="110" width="55">
<image_id>0</image_id> <-- error
<caption>some caption</caption>
</image_slot>
QXmlSchemaValidator驗證XSD,但不是針對XSD的XML。擺脫substitutionGroup足以驗證XML,但這也意味着我失去了功能 - 現在將驗證不正確的XML文件。因此,我的問題是 - Qt實際上是否支持XML substitutionGroups,並且還有其他的我做錯了(其他工具沒有注意到)?
或者它是QXmlSchemaValidator中的一個錯誤,在這種情況下,我應該放棄這個想法並找到另一個解決方案?
編輯:不得不等待一天才能發佈我自己的答案。我必須再等一天才能接受它。