【发布时间】:2017-07-03 10:38:47
【问题描述】:
我正在尝试读取xsd 文件及其在exception 下方的抛出:
cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '[1-2][0-9]{3,3}(((0[1-9])|(1[0-2]))((0[1-9])|([0-2][0-9]|3[0-1])(([0-1][0-9]|2[0-3])([0-5][0-9]([0-5][0-9](\.[0-9]{1,4})?)?)?)?)?)?([+\-](0[0-9]|1[0-3])([0-5][0-9]))?' for type '#AnonType_valueTS'.
final Schema schema = schemaFactory.newSchema(this.getClass().getClassLoader().getResource("/schemaorg_apache_xmlbeans/src/mySchema.xsd"));
final Validator validator = schema.newValidator();
final StreamSource xmlFile = new StreamSource(new ByteArrayInputStream(xmlString.getBytes("utf-8")));
validator.validate(xmlFile);
这个validator.validate(xmlFile) 部分正在抛出exception。
有什么想法吗?在这里感谢您的帮助。
我已经查看了以下内容:
Value is not facet-valid with respect to pattern
Validating xml. Get the element name that throws cvc-enumeration-valid
【问题讨论】:
-
如果没有看到架构和源文档,就无法判断为什么您的 XML 源代码无效。但是关于您的代码的一点点:如果您在字符串 xmlStr 中有 XML 源,最好使用
new StreamSource(new StringReader(xmlStr))而不是通过字节数组 - 以您的方式,您将面临编码问题的风险。