假設我有我的模式自定義數據類型:如何在我的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可以驗證,除此之外,你需要蘋果橙和香蕉作爲水果類型的元素,然後你可以用序列 –