I would like to know how to return only one error message when an element fails XML schema date validation. My goal was to preserve the validations provided by xs:date (such as February 29, 2015 being invalid due to 2015 not being a leap year), but also ensure that the date is of the pattern with the following regex:
"\d{4}[-]\d{2}[-]\d{2}"
I tried out this in an online XML schema tester, and I got the expected results. The entire schema is as follows:
<xs:schema xmlns:xs="http://ift.tt/tphNwY" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="tripDate">
<xs:simpleType>
<xs:restriction base="xs:date">
<xs:whiteSpace value="collapse"/>
<xs:pattern value="\d{4}[\-]\d{2}[\-]\d{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:element></xs:schema>
And the test element value I used (among others) is:
<tripDate>20115-02-20</tripDate>
When I entered these into the formatter at http://ift.tt/1lmKPLW , I got the following outputs back:
Cvc-pattern-valid: Value '20115-02-20' Is Not Facet-valid With Respect To Pattern '\d{4}[\-]\d{2}[\-]\d{2}' For Type '#AnonType_tripDate'.. Line '1', Column '33'.
Cvc-type.3.1.3: The Value '20115-02-20' Of Element 'tripDate' Is Not Valid.. Line '1', Column '33'.
My question is, how can I ensure that only one error will ever get returned? Specifically, I only want the "Cvc-type" error to be returned, because that comes in the cases when the pattern is invalid, even though the date itself is valid. Is there any kind of schema setting to suppress the "Cvc-pattern-valid" error, or to collapse error into the error of the parent restriction, which in this case is xs:date? I want the "Cvc-type" error only to be returned, because this is what is handled in the Java code for the application, and I am trying not to unnecessarily add Java code to handle the other error as well (at this point it throws an SQL exception error).
Thank you.
Aucun commentaire:
Enregistrer un commentaire