【发布时间】:2016-10-19 10:42:01
【问题描述】:
我想在 grails 中针对 xsd 1.1 验证 xml 文档。
我的验证代码:
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
对于某些转换,我已经使用 Saxon-HE 9.7.0-5
那么我可以做些什么来让我的应用程序针对 XSD 1.1 进行验证?
【问题讨论】:
标签: validation grails xsd saxon