XML Schema 1.1: Implementation of an extension 'message' attribute on assertions
--------------------------------------------------------------------------------
Key: XERCESJ-1441
URL: https://issues.apache.org/jira/browse/XERCESJ-1441
Project: Xerces2-J
Issue Type: Improvement
Components: XML Schema 1.1 Datatypes, XML Schema 1.1 Structures
Affects Versions: 2.10.0
Reporter: Mukul Gandhi
Assignee: Mukul Gandhi
Fix For: 2.10.0
I think, it's useful to allow users to specify an attribute "message" (say in
an extension namespace, "http://xerces.apache.org") on XSD 1.1 assertions. The
value of this attribute will be, the error message string which user's would
want to display, upon assertions failure.
Here's an example of this:
XML document (say, test.xml):
<meeting>2010-01-01 2010-01-07 2010-01-01</meeting>
XSD 1.1 document (say, test.xsd):
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meeting" type="Meeting" />
<xs:simpleType name="Meeting">
<xs:restriction base="Dates" xmlns:xerces="http://xerces.apache.org">
<xs:assertion
test="(count(distinct-values(tokenize($value,'\s+'))) =
count(tokenize($value,'\s+'))) and
(every $d in
tokenize($value,'\s+')[position() lt last()] satisfies
xs:date($d) lt
xs:date(tokenize($value,'\s+')[index-of(tokenize($value,'\s+'), $d) + 1]))"
xerces:message="Dates must be distinct
and must be in ascending order." />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Dates">
<xs:list itemType="xs:date" />
</xs:simpleType>
</xs:schema>
PS: The namespace declaration, xmlns:xerces="http://xerces.apache.org" could be
specified anywhere in the XSD document (say, on xs:schema instruction also), so
that this namespace is in the list of, "in scope namespaces" of an assertions
instruction.
With this particular example, upon XSD 1.1 validation with Xerces, following
error message would be displayed:
[Error] test.xml:1:52: cvc-assertion.failure: Assertion failure. Dates must be
distinct and must be in ascending order.
Whereas, without the attribute "message" on an assertion (or if it's present,
but it contains no significant non-whitespace characters), the following error
message would be displayed:
[Error] test.xml:1:52: cvc-assertion.3.13.4.1: Assertion evaluation ('(count(dis
tinct-values(tokenize($value,'\s+'))) = count(tokenize(
$value,'\s+'))) and (every $d in tokenize($value,'\s+')[position() lt la
st()] satisfies xs:date($d) lt xs:date(tokenize($value,'\s+')[index-of
(tokenize($value,'\s+'), $d) + 1]))') for element 'meeting' with type 'Meeting'
did not succeed.
We could see the benefit of this improvement, as without a user-defined error
message, the assertions error messages (the Xerces provided error messages),
could be quite verbose (and particularly with, large XPath expressions). Also,
using this technique, shall allow user's to specify domain specific error
messages.
I've written a patch for this change, and would be committing it within few
minutes.
Regards,
Mukul
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]