属性のチェックに問題があります。私はこれまで知っていたことをすべて試してきました。腐敗しやすい=いいえいくつかの余分な要素がある場合は、その場合、腐敗しやすいものとは異なる要素がある=いいえ。私はグループを試してみたが、うまくいきませんでした。私は食品と在庫をグループ化することを考えていましたが、生鮮食品にはその制限があります。腐敗しやすい場合にのみ、私たちは食べ物の要素を持っています。助けてください!!! XSI:type属性あなたは一つの例外を除いて、要素の内容モデルを制御するために属性を使用することはできませんXMLスキーマの構造、異なる値を持つ同じ要素を持つxmlにはスキーマが必要です
<product id = "p12" perishable = "yes">
<name>Ice cream</name>
<manufacturer>xsz Co.</manufacturer>
<quantity>25</quantity>
<price>2</price>
<food>
<nutrition>
<calcium>10.30</calcium>
<proteins>35.5</proteins>
<fat>10</fat>
</nutrition>
<expirationDate>2000-09-12</expirationDate>
</food>
</product>
<product id = "p13" perishable = "no">
<name>AA Battries</name>
<manufacturer>DCells</manufacturer>
<quantity>100</quantity>
<price>4</price>
<stock>
<warehouse id = "w12">
xsz warehouse
<stock>25000</stock>
</warehouse>
<warehouse id = "w13">
rza warehouse
<stock>5000</stock>
</warehouse>
</stock>
</product>
<!-- defining the nutrition element for the perishable product -->
<xs:element name="nutrition">
<xs:complexType>
<xs:sequence>
<xs:element name="calcium" type="xs:decimal"/>
<xs:element name="proteins" type="xs:decimal"/>
<xs:element name="fat" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- defining the group product that is perishable -->
<xs:group name="perishableGroup">
<xs:sequence>
<xs:element name="product">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="manufacturer" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<xs:element name="food">
<xs:complexType> <!-- defining the food element for perishable product -->
<xs:sequence>
<xs:element ref="nutrition"/> <!-- defined above -->
<xs:element name="expirationDate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="perishable" type="xs:string" use="required" fixed="yes"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:group>
<!-- defining the group product that is nonperishable -->
<xs:group name="nonperishableGroup">
<xs:sequence>
<xs:element name="product">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="manufacturer" type="xs:string"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
<xs:element name="stock">
<xs:complexType>
<xs:sequence>
<xs:element name="warehouse" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="stock" type="xs:positiveInteger"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="perishable" type="xs:string" use="required" fixed="no"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:group>
<xs:element name="products">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:group ref="perishableGroup"/>
<xs:group ref="nonperishableGroup"/>
</xs:choice>
</xs:complexType>
</xs:element>
P.S.あなたが物事を変えることができるならば、傷みやすい属性を傷みやすい要素と腐敗しない要素の間の選択肢に変えてください。それは物事をあなたのために簡単にするだろう、と私は思う。 – Kevin
私はXML文書をそのまま検証しなければなりません。私は生鮮で腐敗しないものを使うことはできません。腐敗しやすいものでなければなりません。しかし、ありがとう – Keisha