我想在grails中驗證xml文檔對抗xsd 1.1的效果。Grails根據xsd驗證xml文檔1.1
我對驗證碼:
def checkXmlAgainstXsd(InputStream xsd, InputStream xml) throws IOException, SAXException {
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(xsd))
def validator = schema.newValidator()
validator.validate(new StreamSource(xml))
}
我如何可以驗證對XSD 1.1嗎?
當我嘗試這樣的xsd:
<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="WaitForSoap">
<xs:complexType mixed="true">
<xs:all>
<xs:element name="Firstname" maxOccurs="3">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Lastname" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
我得到的錯誤:
org.xml.sax.SAXParseException; lineNumber: 5;
columnNumber: 9; cos-all-limited.2: The {max occurs} of an
element in an 'all' model group must be 0 or 1
對於一些轉變,我已經使用撒克遜-HE 9.7.0-5
所以什麼都可以我確實讓我的應用程序在XSD 1.1上驗證了嗎?