I want to validate the generated xml, with the xsd file. But I got the following error message.
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/ibm/icu/text/UTF16
Here's my code:
public void validateAgainstXSD(File xml) {
try {
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1");
Schema schema = factory.newSchema(new File(xsdFilepath));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(xml));
System.out.println("success");
} catch (Exception ex) {
ex.getMessage();
}
}
And the error message is in the following line:
validator.validate(new StreamSource(xml));
Does anyone know why that happened? And what is the solution for successful validation? I really need your help, thank you.
Finally I found where the error lies. The error is in the following XSD:
<xs:simpleType name="nameNType">
<xs:restriction base="xs:string">
<xs:assertion test="string-length($value) <= 65"/>
</xs:restriction>
</xs:simpleType>
If I comment on the code snippet above, it has been successfully validated and no error message appears as above.
Another question, what is the format so that I can still use the xsd code snippet? How to change it to UTF-8?