CVC图案有效:值“”不是刻面的有效相对于模式
问题描述:
我想读xsd
文件及其投掷下面exception
:CVC图案有效:值“”不是刻面的有效相对于模式
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
答
你的XSD指定Value
必须在指定的正则表达式,不允许一个空字符串相匹配。
要么将Value
更改为符合XSD的正则表达式的非空值,要么将正则表达式更改为允许空字符串。
+0
谢谢了,价值是空的,我没有认出它:) – DMM
如果没有看到架构和源文档,就无法说明您的XML源无效的原因。但是有一点关于你的代码:如果你在一个字符串xmlStr中有XML源代码,最好是用新的StreamSource(新的StringReader(xmlStr))而不是通过一个字节数组来执行 - 你冒着风险编码问题。 –