Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1441

XML Schema 1.1: Implementation of an extension 'message' attribute on assertions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.9.1
    • 2.10.0
    • None

    Description

      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

      Attachments

        Activity

          People

            mukul_gandhi Mukul Gandhi
            mukul_gandhi Mukul Gandhi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: