Hi all,
I have made quite a bit of progress in implementing assertions, but
facing a small difficulty at present. Kindly find below the problem I
am facing.
I am writing code into the class, XMLSchemaValidator.java and facing
some difficulty generating error messages on the console.
In the method, 'endElement' I am evaluating assertions as following:
XMLAssert assertionProcessor = new XMLAssertPsychopathImpl();
try {
// some code
boolean isAssertTrue = assertionProcessor
.evaluateXpathExpression(assertImpl.getTest().getXPath()
.toString());
if (!isAssertTrue) {
String typeName = fCurrentPSVI.getTypeDefinition().getAnonymous()
? "anonymous type" : fCurrentPSVI.getTypeDefinition().getName();
reportSchemaError("cvc-xpath.3.13", new Object[] {
element.rawname,
assertImpl.getTest().getXPath().toString(),
typeName});
}
// some code
}
catch (Exception ex) {
throw new XNIException(ex.getMessage());
}
In the file, XMLSchemaMessages.properties I have created a message key
as following:
cvc-xpath.3.13 = cvc-xpath.3.13: Assertion evaluation (''{1}'') for
element ''{0}'' with type ''{2}'' did not succeed.
But in the above code, the 'reportSchemaError' call is throwing a Java
exception, and the control goes to the catch (Exception ex) block, and
the program ends with following message on console (produced by the
call, throw new XNIException):
org.xml.sax.SAXException: cvc-xpath.3.13: Assertion evaluation ('1=2')
for element 'X' with type 'myComplexType1
' did not succeed.
at org.apache.xerces.jaxp.validation.Util.toSAXException(Util.java:63)
at
org.apache.xerces.jaxp.validation.StreamValidatorHelper.validate(StreamValidatorHelper.java:187)
at
org.apache.xerces.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:129)
at javax.xml.validation.Validator.validate(Unknown Source)
at XMLSchema11Test.main(XMLSchema11Test.java:15)
In this particular case, the following assert declaration in the
Schema, fails: <xs:assert test="1=2" />. And it should indeed fail.
But I want to display an user friendly error message in this case.
Why does the 'reportSchemaError' method call fails, and how could I
fix this problem?
--
Regards,
Mukul Gandhi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]