4

I have an XSD where I want to use an xs:assert statement. The issue is I don't know how to make the assert functionality available to me. I am using Visual Studio to write it, and it gets a blue line saying it doesn't support the assert element.

My XSD looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns="http://www.client.co.uk/quote" 
           targetNamespace="http://www.client.co.uk/quote" 
           elementFormDefault="qualified" 
           attributeFormDefault="unqualified">

<xs:element name="ProductType" type="ProductCodeType"/>
  <xs:simpleType name="ProductCodeType">
    <xs:annotation>
      <xs:documentation>Client Product Type</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="L" />
      <xs:enumeration value="C" />
      <xs:enumeration value="H" />
    </xs:restriction>
  </xs:simpleType>

  <xs:element name="BenefitBasisType">
    <xs:simpleType>
      <xs:annotation>
        <xs:documentation>Client benefit basis type</xs:documentation>
      </xs:annotation>
      <xs:assert test= "if (ProductType = 'L') then $value = 'M' else if (ProductType = 'C') then $value = 'F' else if (ProductType = 'H') $value = 'P'" />
      <xs:restriction base="xs:string">
        <xs:enumeration value="M" />
        <xs:enumeration value="F" />
        <xs:enumeration value="P" />
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Tobias
  • 67
  • 1
  • 2
  • 6

1 Answers1

4

The problem is that xs:assert requires XSD 1.1, and Microsoft Visual Studio only supports XSD 1.0. You'll have to use an XML processor that supports XSD 1.1 such as one of the following:

Abel
  • 56,041
  • 24
  • 146
  • 247
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • are there any add ons to visual studio that allow use of 1.1 XSD? – Tobias Sep 10 '15 at 12:33
  • Some of Altova's products integrate with Visual Studio, I don't know if this is true of their XSD processor. – Michael Kay Sep 10 '15 at 13:06
  • 1
    @Tobias, consider upvoting [this UserVoice post on XSD 1.1](https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3109674-xsd-1-1-support), to urge MS to add this. In addition, Saxon has a .NET version, so you can use that. If you want to validate from within the editor, use oXygen, Stylus Studio, Altova, Eclipse. – Abel Sep 10 '15 at 15:40