【问题标题】:How to resolve cvc-pattern-valid: Value '' is not facet-valid with respect to pattern problem如何解决 cvc-pattern-valid: Value '' is not facet-valid 关于模式问题
【发布时间】: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)) 而不是通过字节数组 - 以您的方式,您将面临编码问题的风险。

标签: java xml xsd sax


【解决方案1】:

您的 XSD 指定 Value 必须匹配一个不允许空字符串的指定正则表达式。

要么将Value 更改为符合XSD 正则表达式的非空值,要么将正则表达式更改为允许空字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    相关资源
    最近更新 更多