QXmlSchemaValidator(Qt4.8)是否支持XML模式(XSD)属性;替换组“;
当我的XML包含替换组时,QXmlSchemaValidator不会验证它。在线工具(,)根据XSD验证XML、XSD和XML 错误:QXmlSchemaValidator(Qt4.8)是否支持XML模式(XSD)属性;替换组“;,xml,qt,xsd,Xml,Qt,Xsd,当我的XML包含替换组时,QXmlSchemaValidator不会验证它。在线工具(,)根据XSD验证XML、XSD和XML 错误: 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:elemen
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>
0结果表明,取代基的元素必须是相同类型的。在我的XSD中就是这样,但是类型是在组的每个元素中定义的,而不是在抽象元素级别定义的。以下代码解决了该问题:
XDS代码:
<xs:element name="image_ids" type="xs:nonNegativeInteger" abstract="true"/>
<xs:element name="image_id" substitutionGroup="image_ids"/>
<xs:element name="image_queue_id" 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>
<caption>some caption</caption>
</image_slot>
0
一些标题
我不确定为什么QXmlSchemaValidator验证模式后却拒绝验证XML;希望这能帮助其他面临同样问题的人