我想限制XML模式到一個特定的集合。我閱讀本教程如何用XML Schema限制xml?
http://www.w3schools.com/schema/schema_facets.asp
這似乎是我想要的。所以,我使用Qt來驗證這個xml
<car>BMW</car>
這裏是相關的源代碼。
QXmlSchema schema;
schema.load(QUrl("file:///workspace/QtExamples/ValidateXSD/car.xsd"));
if (schema.isValid()) {
QXmlSchemaValidator validator(schema);
if (validator.validate(QUrl("file:///workspace/QtExamples/ValidateXSD/car.xml"))) {
qDebug() << "instance is valid";
} else {
qDebug() << "instance is invalid";
}
} else {
qDebug() << "schema is invalid";
}
我希望xml匹配模式定義。意外的是,QxmlSchemaValidator抱怨。
錯誤XSDError在文件:///workspace/QtExamples/ValidateXSD/car.xml,位於第1行,第5欄:元件車的內容不匹配其類型定義:字符串內容未在枚舉中列出方面..
實例無效
我懷疑這是一個braino。如何用XML Schema限制xml?
下面是本教程的XSD:
<xs:element name="car">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi"/>
<xs:enumeration value="Golf"/>
<xs:enumeration value="BMW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
您能否顯示xsd? – 2010-06-04 23:25:33
看起來像一個xsd問題,而不是一個Qt問題。是的,請向我們展示xsd。 – 2010-06-06 07:53:13
感謝您的意見。 xsd是教程的一部分。希望反引用的作品也可以在評論中轉義代碼。 ' xs:restriction> xs:simpleType> ' –
John
2010-06-07 13:57:11