Dear Wiki user, You have subscribed to a wiki page or wiki category on "Xerces Wiki" for change notification.
The "XML_Schema_1.1_Assertions" page has been changed by Mukul Gandhi. http://wiki.apache.org/xerces/XML_Schema_1.1_Assertions?action=diff&rev1=109&rev2=110 -------------------------------------------------- The Xerces XSModel (an object model representing an XML Schema) is modified to handle assertions, for the XML Schema 1.1 Simple and Complex types. - Since "assertion" is now a new facet (a constraining facet) in XSD 1.1, for XML Schema Simple types, the current facet data structures, and the facet traverser (traverser is a mechanism used by Xerces to populate XSModel, from XSD syntax) are enhanced to support XML Schema 1.1 assertions. + Since "assertion" is also now a new facet (a constraining facet) in XSD 1.1, for XML Schema Simple types, the current facet data structures, and the facet traverser (traverser is a mechanism used by Xerces to populate XSModel, from XSD syntax) are enhanced to support XML Schema 1.1 assertions. To implement assertions for Complex types, the Complex type traverser of Xerces is modified. @@ -122, +122 @@ 1. If user's wish to use an XPath 2.0 engine other than PsychoPath, for working with Xerces-J assertions, they need to write a custom Java layer similar to org.apache.xerces.impl.xs.XMLAssertPsychopathImpl, and integrate it with their own XPath 2.0 engine, using the XPath 2.0 engine's APIs. Xerces-J would publish an API, to integrate to any available standard compliant XPath 2.0 engines. 1. Error codes, and descriptions: + Xerces-J flags error messages during assertions processing, as recommended by the XML Schema 1.1 specification. Here's the summary of error codes/messages, used by Xerces during assertion processing: - a. '''cvc-assertion.3.13.4.1''' -> Xerces uses this error code, with a description like following "test.xml:3:11:cvc-assertion.3.13.4.1: Assertion evaluation ('x = 'hello world'') for element 'Example' with type '#anonymous' did not succeed.", when any of the assertions evaluate to false. + a. '''cvc-assertion.3.13.4.1''' -> Xerces uses this error code, with a description like following "test.xml:3:11:cvc-assertion.3.13.4.1: Assertion evaluation (x = 'hello world') for element 'Example' with type '#anonymous' did not succeed.", when any of the assertions evaluate to false. a. '''cvc-assertion.3.13.4.1''' -> Here's an example of error description, when an assertion facet on a attribute value, evaluates to false: "test.xml:2:18:cvc-assertion.3.13.4.1: Assertion evaluation ('$value eq 2') for element 'x (attribute => a)' with type '#anonymous' did not succeed.". - a. '''cvc-assertion.4.3.15.3''' -> This error code is used, with a description like following "test.xml:2:15:cvc-assertion.4.3.15.3: Assertion evaluation ('. = 'hello'') for element 'x' with type '#anonymous' did not succeed (undefined context).", when an attempt is made to access the XPath context (for e.g, with the expression "."), during assertion facet evaluation. + a. '''cvc-assertion.4.3.15.3''' -> This error code is used, with a description like following "test.xml:2:15:cvc-assertion.4.3.15.3: Assertion evaluation (. = 'hello') for element 'x' with type '#anonymous' did not succeed (undefined context).", when an attempt is made to access the XPath context (for e.g, with the expression "."), during assertion facet evaluation. - a. '''cvc-xpath.3.13.4.2''' -> This error code is used, with a description like following "cvc-xpath.3.13.4.2: Assertion XPath expression, ('. === 'hello'') on the Schema type '#AnonType_xExample' couldn't compile successfully.", when a syntactically wrong XPath expression, is provided for assertion evaluation. + a. '''cvc-xpath.3.13.4.2''' -> This error code is used, with a description like following "cvc-xpath.3.13.4.2: Assertion XPath expression, (. === 'hello') on the Schema type '#AnonType_xExample' couldn't compile successfully.", when a syntactically wrong XPath expression, is provided for assertion evaluation. + a. Xerces allows schema authors to specify user-defined error messages, to be produced during assertions failures. Here's an example illustrating this feature: + + XML document [3]: + + <test>3</test> + + XSD 1.1 schema document [4]: + + <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> + + <xs:element name="test"> + <xs:simpleType> + <xs:restriction base="xs:positiveInteger" xmlns:xerces="http://xerces.apache.org"> + <xs:assertion test="$value mod 2 = 0" xerces:message="Value of element 'test' must be divisible by 2" /> + </xs:restriction> + </xs:simpleType> + </xs:element> + + </xs:schema> + + When the above XML document [3], is validated with the corresponding schema document [4], following error message is displayed: + + "test.xml:1:15: cvc-assertion.failure: Assertion failure. Value of element 'test' must be divisible by 2." + + Notes: + 1. The user-defined error messages on assertions, needs to be specified as a value, of attribute "message" (which needs to be in the XML namespace, "http://xerces.apache.org") on xs:assert/xs:assertion instruction. + 1. The mechanism of specifying user-defined error messages on XSD 1.1 assertions in Xerces-J, may change in future, if XSD WG suggests a specific guidance in the final XSD 1.1 language recommendation, regarding this. '''References:''' --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
