
When the XML document is loaded the XPath expression in the xs:assert element is evaluated, if it does not evaluate to true, a validation error is raised.
This mechanism provides the ability to provide cross field validation, something that has been lacking in the XSD 1.0 standard.
An xs:assert can be added to the following XSD entities
This can be done using the right click context menu on any of these entities.
Id | A user defined ID to uniquely identify the entity within the schema |
Test | The XPath expression that must be true for the XML document to be considered valid |
XPath Default Namespace | The default namespace used in the XPath expression 'Test'. |
The following XSD code
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Example"> <xs:complexType> <xs:sequence> <xs:element name="paragraph" type="paragraphType" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="paragraphType" mixed="true"> <xs:sequence> <xs:element name="table" type="xs:string" minOccurs="0" /> <xs:element name="paragraph" type="paragraphType" minOccurs="0" /> </xs:sequence> <xs:assert test="if (paragraph) then paragraph/preceding-sibling::table else true()" /> </xs:complexType> </xs:schema>
Sample XML would look like this
<?xml version="1.0" encoding="utf-8"?> <Example> <paragraph> <table>Table 1</table> <paragraph>Paragraph 1</paragraph> </paragraph> </Example>
Properties that apply to a type are shown inline at the bottom of the items container.
Values that are inherited from the base types are shown in brackets, values specifically set against the item are shown without brackets.
If a facet is not valid for a given type (typically because of its data type), then its value is shown in red.