Altova XMLSpy 2025 Enterprise Edition

Assertion Messages

Home Prev Top Next

In XML Schema 1.1, assertions can be defined for complex types (using xs:assert elements) and simple types (using xs:assertion elements).

 

It is very useful if an explanation of the assertion is supplied together with its definition, so that in case the assertion is not fulfilled when the XML instance document is validated, an appropriate message can be displayed. Since the XML Schema specification does not make provision for such a message, XMLSpy allows a message in the Altova xml-schema-extensions namespace https://www.altova.com/xml-schema-extensions (or any other namespace) to be provided with the definition of the assertion and to be used in the validation of the XML instance document. For example:

 

<xs:assert test="count(//MyNode) ge 1" altova:message="There must be at least one MyNode element"/> or

<xs:assertion test="count(//MyNode) ge 1" altova:message="There must be at least one MyNode element"/>

 

If the restriction specified in the assertion is not fulfilled, XMLSpy's validation engine will display, along with the validation-error message, the message associated with the assertion as a hint. The validator will report the value of an assert/@message attribute or of an assertion/@message attribute regardless of the namespace in which the message attribute is. However, in Schema View, you can edit only message attributes that are in the Altova xml-schema-extension namespace. To edit message attributes in other namespaces, use Text View.

 

 

Editing xs:assert messages

In Schema View, xs:assert elements (for complex types) can be created and edited in the Attributes/Assertions/Identity Constraints (AAIDC) pane or Details entry helper of the relevant complex type. The screenshot below shows an assertion for the complex type orderType. The assertion (an xs:assert in this case) is defined in the Assertions tab (of Schema Overview) together with an assertion message.

AssertMessageXSD01

If the Display Assertions in Diagram option is selected, assertions on complex types can also be created and edited in Content Model View. To add or edit an assertion message, select the assertion and enter the assertion message in the Details entry helper (see screenshot below).

AssertMessageXSD02

Note that assertion messages created in this way are in the Altova xml-schema-extensions namespace https://www.altova.com/xml-schema-extensions. When you add the first assertion message in the XML schema document via the AAIDC pane or Details entry helper, the Altova xml-schema-extensions namespace is automatically declared on the xs:schema element.

 

If an XML file is validated and the assertion test is not fulfilled, the message defined for the assertion is displayed together with an error message (see screenshot below).

AssertMessageXML

 

Editing xs:assertion messages

In Schema View, xs:assertion elements (for simple types) can be created and edited in the Facets entry helper of the relevant simple type. To edit the assertion message, right-click the assertion in the Facets entry helper (see screenshot below), click Details in the menu that pops up, and edit the message in the Assertion Details modal window (see screenshot below). Note that assertion messages created in this way are in the Altova xml-schema-extensions namespace https://www.altova.com/xml-schema-extensions. When you add the first assertion message in the XML schema document via the Assertion Details modal window, the namespace is automatically declared on the xs:schema element.

AssertionMessageXSD

If an XML file is validated and the assertion test is not fulfilled, the message defined for the assertion is displayed together in the error message (see screenshot below).

AssertionMessageXML

 

© 2018-2024 Altova GmbH