0
我有一个属性(类),其可采取任何2个值的父元素(产物)(腐烂,和不易腐烂)。如果该项目是易腐,我希望有子元素“食品”,如果它不容易变质,我想拥有的子元素“股票”。从看,我收集,这可以在XSD 1.1,但不是XSD 1.0。但是,我没有找到如何做到这一点。XML模式选择基于父项的子元素属性
下面是我的代码,缩短展示的重要组成部分:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="products">
<xs:complexType>
<xs:sequence>
<xs:element name="product" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:element name="food">
<xs:complexType>
/*DEFINED FOOD HERE*?
</xs:complexType>
</xs:element>
<xs:element name="stock">
<xs:complexType>
/*DEFINED STOCK HERE*/
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="category">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="perishable"/>
<xs:enumeration value="nonPerishable"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
谁能帮助我吗?
对不起echew,这dosent帮助。请重新阅读第一段:) – 2013-02-23 23:40:46
给我一个例子,说明如何让xml看起来像。 如果元素不符合易腐标准,您是否希望元素定义为不易变质? – echew 2013-02-23 23:49:38
产品具有一个属性,该属性可以具有易腐性或非易腐性作为其值。如果属性的值是易腐烂的,我想要一个食品元素在产品元素中。如果该属性的值为nonPerishable,那么我需要产品元素中的库存元素 – 2013-02-24 13:45:58