2015-09-10 132 views
2

我有一個XSD,我想要使用xs:assert語句。問題是我不知道如何使斷言功能可用。我正在使用Visual Studio編寫它,並且它得到一條藍線,表示它不支持assert元素。XSD斷言無法識別

我的XSD看起來是這樣的:

<?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> 

回答

2

的問題是,xs:assert需要XSD 1.1,和Microsoft Visual Studio僅支持XSD 1.0。你必須使用支持XSD 1.1以下,如一個XML處理器:

+0

是否有任何附加是否允許使用1.1 XSD的視覺工作室? – Tobias

+0

Altova的一些產品與Visual Studio集成,我不知道他們的XSD處理器是否屬實。 –

+1

@Tobias,考慮提升[此XSD 1.1上的此UserVoice帖子](https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3109674-xsd-1-1-support),以敦促MS添加這個。此外,撒克遜有一個.NET版本,所以你可以使用它。如果您想從編輯器中進行驗證,請使用oXygen,Stylus Studio,Altova,Eclipse。 – Abel