问题
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>
回答1:
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:
- Xerces-J with PsychoPath XPath 2.0
- Saxon EE
- Altova
- Liquid XML also supports it
来源:https://stackoverflow.com/questions/32500445/xsd-assert-not-recognised