2016-11-29 17 views
1

thisオンラインバリデータを使用して、私のファイルを検証しながら、私はエラーメッセージを以下の取得:連合要素の検証XMLスキーマ

CVC-データ型-valid.1.2.3:「Gomorra 20140506」は 組合の有効な値ではありません'#AnonType_alternatywny_tekstzdjecie'と入力します。

cvc-type.3.1.3: 'alternatywny_tekst'の値 'Gomorra 20140506'は無効です。

私はw3schoolsの例のようにコードを作成しました。誰かが私のコードに何が間違っているのか教えてもらえますか?

<xs:element name="zdjecie"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="wysokosc" type="xs:decimal"/> 
     <xs:element name="szerokosc" type="xs:decimal"/> 
     <xs:element ref="zrodlo"/> 
     <xs:element name="alternatywny_tekst"> 
     <xs:simpleType> 
      <xs:union memberTypes="tekst_1 tekst_2"/> 
     </xs:simpleType> 
     </xs:element> 
    </xs:sequence> 
    <xs:attribute ref="kod"/> 
    </xs:complexType> 
</xs:element> 

<xs:simpleType name="tekst_1"> 
    <xs:restriction base="xs:string"> 
    <xs:enumeration value="Gomorra"/> 
    <xs:enumeration value="Grand Budapest Hotel"/> 
    <xs:enumeration value="Fargo"/> 
    <xs:enumeration value="Wściekłe psy"/> 
    </xs:restriction> 
</xs:simpleType> 

<xs:simpleType name="tekst_2"> 
    <xs:restriction base="xs:integer"> 
    <xs:maxExclusive value="20161130"/> 
    </xs:restriction> 
</xs:simpleType> 

XML

<zdjecie kod="GO.2014.001"> 
    <wysokosc>735</wysokosc> 
    <szerokosc>500</szerokosc> 
    <zrodlo>Obrazki/gomorra.jpg</zrodlo> 
    <alternatywny_tekst>Gomorra 20140506</alternatywny_tekst> 
</zdjecie> 

答えて

1

xs:unionの値空間は、そのメンバーの種類の労働組合ですが、それだけでは、複数のメンバーが存在することはできません。あなたのXMLから、あなたは複数のメンバーを許可したいと思うようです。あなたはxs:listを経由して、これを達成することができます

<xs:element name="alternatywny_tekst"> 
     <xs:simpleType> 
     <xs:list> 
      <xs:simpleType> 
      <xs:union memberTypes="tekst_1 tekst_2"/> 
      </xs:simpleType> 
     </xs:list> 
     </xs:simpleType> 
    </xs:element> 

注これはtekst_1tekst_2によって許可された値の和集合からの組み合わせを可能にすること - 必ずしもtekst_2続いtekst_1。ここで

正常にXMLを検証します完全なXSDの文脈で上記の宣言です:

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="zdjecie"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="wysokosc" type="xs:decimal"/> 
     <xs:element name="szerokosc" type="xs:decimal"/> 
     <xs:element name="zrodlo" type="xs:string"/> 
     <xs:element name="alternatywny_tekst"> 
      <xs:simpleType> 
      <xs:list> 
       <xs:simpleType> 
       <xs:union memberTypes="tekst_1 tekst_2"/> 
       </xs:simpleType> 
      </xs:list> 
      </xs:simpleType> 
     </xs:element> 
     </xs:sequence> 
     <xs:attribute name="kod" type="xs:string"/> 
    </xs:complexType> 
    </xs:element> 
    <xs:simpleType name="tekst_1"> 
    <xs:restriction base="xs:string"> 
     <xs:enumeration value="Gomorra"/> 
     <xs:enumeration value="Grand Budapest Hotel"/> 
     <xs:enumeration value="Fargo"/> 
     <xs:enumeration value="Wściekłe psy"/> 
    </xs:restriction> 
    </xs:simpleType> 
    <xs:simpleType name="tekst_2"> 
    <xs:restriction base="xs:integer"> 
     <xs:maxExclusive value="20161130"/> 
    </xs:restriction> 
    </xs:simpleType> 
</xs:schema> 
関連する問題