3
votes

I am trying to read xsd file and its throwing below 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);

This validator.validate(xmlFile) part is throwing exception.

Any Idea? Appreciate your kind help here.

and I have already looked in to below: Value is not facet-valid with respect to pattern

Validating xml. Get the element name that throws cvc-enumeration-valid

1
Can't tell why your XML source is invalid without seeing the schema and source document. But a little point about your code: if you have XML source in a string xmlStr, it's best to do new StreamSource(new StringReader(xmlStr)) rather than going via a byte array - with your way, you run the risk of encoding problems.Michael Kay

1 Answers

4
votes

Your XSD specifies that Value must match a specified regular expression that does not allow an empty string.

Either change Value to be a non-empty value that conforms to the XSD's regex, or change the regex to allow an empty string.