2017-09-18 3 views
2

XSDファイルを使用してxmlファイルを検証しようとしているときに、The Content Of 'all' Must Match (annotation?, Element*). A Problem Was Found Starting At: Sequence.というエラーが表示されます。サブルートノードでsizeの番号が変更される可能性があるため、<xs:all>を使用しました。また、属性タグを<xs:all>タグの前後に追加するかどうかはわかりません。エラー: 'all'の内容が一致する必要があります

これは私のxmlファイル

<?xml version="1.0" encoding="UTF-8"?> 
 
<catalog> 
 
    <product description="Cardigan Sweater" product_image="cardigan.jpg"> 
 
     <catalog_item gender="Men's"> 
 
     <item_number>QWZ5671</item_number> 
 
     <price>39.95</price> 
 
     <size description="Medium"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
     </size> 
 
     <size description="Large"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
     </size> 
 
     </catalog_item> 
 
     <catalog_item gender="Women's"> 
 
     <item_number>RRX9856</item_number> 
 
     <price>42.50</price> 
 
     <size description="Small"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
     </size> 
 
     <size description="Medium"> 
 
      <color_swatch image="red_cardigan.jpg">Red</color_swatch> 
 
      <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
      <color_swatch image="black_cardigan.jpg">Black</color_swatch> 
 
     </size> 
 
     <size description="Large"> 
 
      <color_swatch image="navy_cardigan.jpg">Navy</color_swatch> 
 
      <color_swatch image="black_cardigan.jpg">Black</color_swatch> 
 
     </size> 
 
     <size description="Extra Large"> 
 
      <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch> 
 
      <color_swatch image="black_cardigan.jpg">Black</color_swatch> 
 
     </size> 
 
     </catalog_item> 
 
    </product> 
 
</catalog>
であり、これは私のXSDファイルです。私が正しい場所に配置されているかどうかはわかりません。あなたは <catalog_item>のいくつかの <size>の要素をできるようにしたいと仮定すると、

<?xml version="1.0"?> 
 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
 
    <xs:element name="catalog"> 
 
    <xs:complexType> 
 
    <xs:sequence> 
 
    <xs:element name="product"> 
 
     <xs:complexType> 
 
     <xs:sequence> 
 
     <xs:element name="catalog_item"> 
 
     <xs:complexType> 
 
      <xs:sequence> 
 
      <xs:element name="item_number"> 
 
      <xs:simpleType> 
 
      <xs:restriction base="xs:string"> 
 
       <xs:pattern value="[A-Z][A-Z][A-Z][0-9][0-9][0-9][0-9]"/> 
 
      </xs:restriction> 
 
      </xs:simpleType> 
 
      </xs:element> 
 
      <xs:element name="price" type="xs:decimal"/> 
 
      <xs:element name="size"> 
 
      <xs:complexType> 
 
      <xs:all minOccurs="1"> 
 
       <xs:sequence> 
 
       <xs:element name="color_swatch" type="xs:string"> 
 
       <xs:complexType> 
 
       <xs:sequence minOccurs="1" maxOccurs="unbounded"> 
 
       </xs:sequence> 
 
\t \t \t \t <xs:attribute name="image" type="xs:string"/> 
 
       </xs:complexType> 
 
       </xs:element> 
 
       </xs:sequence> 
 
\t \t \t <xs:attribute name="description" type="xs:string"/> 
 
      </xs:all> 
 
      </xs:complexType> 
 
      </xs:element> 
 
\t \t </xs:sequence> 
 
\t \t <xs:attribute name="gender" type="xs:string"/> 
 
\t \t </xs:complexType> 
 
     </xs:element> 
 
\t </xs:sequence> 
 
\t <attribute name="description" type="xs:string"/> 
 
    <attribute name="product_image" type="xs:string"/> 
 
    </xs:complexType> 
 
    </xs:element> 
 
    </xs:sequence> 
 
    </xs:complexType> 
 
</xs:element> 
 
</xs:schema>

答えて

3

、あなたはsize要素にmaxOccurs="unbounded"を設定する必要があります。

<xs:element name="size" maxOccurs="unbounded"> 

その後、あなたは<size>のコンテンツの定義を修正する必要があります - ここ<xs:all>を使用しない点がありません(<xs:all>は「どんな順序、論文要素は、この文脈で一度だけ発生する必要がある」を意味することを覚えておいてください)。これはあなたの要件を満たす必要があります。

<xs:element name="size" maxOccurs="unbounded"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="color_swatch" maxOccurs="unbounded"> 
       <xs:complexType mixed="true"> 
        <xs:attribute name="image" type="xs:string"/> 
       </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
      <xs:attribute name="description" type="xs:string"/> 
     </xs:complexType> 
    </xs:element> 

PSを:

<attribute name="description" type="xs:string"/> 
<attribute name="product_image" type="xs:string"/> 
+1

現在の問題を解決する:あなたは、最後の2つの属性の宣言の「xs:」プレフィックスを忘れてしまいました。しかし、今、私はエラーが発生しました "無効なコンテンツは、 'catalog_item'要素で始まる要素で始まっていないと言っています。この時点で子要素はありません。 '15'列、 '38'列" このエラーはxmlファイル。なぜなら、私のxsdファイルで定義されている 'color_swatch'要素は、xmlに複数の要素を持たせることができないからですか? –

+0

おそらく 'maxOccurs =" unbounded "を' 'に設定する必要があります。 – potame

関連する問題