假设我有我的模式自定义数据类型:如何在我的XML模式中需要自定义数据类型的特定实例?
<xs:element name="Fruit">
<xs:complexType>
<xs:sequence>
<xs:element ref="Name"/>
<xs:element ref="Supplier"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Name" type="xs:NCName"/>
<xs:element name="Supplier" type="xs:string"/>
其他地方我想要求水果的特定实例的架构,所以我有类似如下的XML文件:
<fruits>
<common>
<!-- the common section should always include Fruits with these Names -->
<Fruit>
<Name>apple</Name>
<Supplier>Shady Orchard</Supplier>
</Fruit>
<Fruit>
<Name>orange</Name>
<Supplier>Florida Orange Co.</Supplier>
</Fruit>
<Fruit>
<Name>banana</Name>
<Supplier>Bananaland</Supplier>
</Fruit>
</common>
<exotic>
<Fruit>
<Name>kiwano</Name>
<Supplier>Fancy Fruits</Supplier>
</Fruit>
<Fruit>
<Name>rambutan</Name>
<Supplier>Indonesia Fruit Co.</Supplier>
</Fruit>
<!-- the list goes on... -->
</exotic>
</fruits>
我知道我可以定义在我的文件中像这样的异国部分:
<xs:element name="exotic">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Fruit"/>
</xs:sequence>
</xs:complexType>
</xs:element>
但是我怎么定义共同部分,这样Fruit
s的名字苹果,橙色和香蕉总是需要?
我不知道我明白。您希望创建元素,该元素仅允许将某些类型的水果作为子元素,并且允许接受所有水果的元素。是对的吗?或者,您可能希望元素实际上需要三种最受欢迎的水果 –
toniedzwiedz
是的,这是您提到的最后一件事,我坚持 - 我希望元素需要这三个特定的成果。 –
rob
不要以为你可以在xsd中做到这一点,当然我不能想出一种定义这种方式的方法。 Schematron可以验证,除此之外,你需要苹果橙和香蕉作为水果类型的元素,然后你可以用序列 –