所以我在檢查屬性時遇到問題。到目前爲止,我已經嘗試了我所知道的一切,但它沒有奏效。如果易腐=否有一些額外的元素,如果是的話那麼就有一些不同的元素來自易腐=不。我試過團體,但它沒有奏效。我正在考慮將食物和庫存分組,但是對於易腐爛的食物有限制。只有在易腐爛的情況下,我們纔有食物元素,如果不存在,我們就有存貨元素。請幫助!!!XML Schema構造,具有不同值的相同元素的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 2012-02-09 19:23:18
我必須按原樣驗證xml文檔。我不能使用易腐爛和不易腐爛的東西,它必須是易腐爛的。非常感謝 – Keisha 2012-02-09 22:03:59