我有一個如下所示的XML文件,並希望使用類型替換方法創建XML模式,以便它可以驗證下面的XML文件。但是我創建的模式是完全錯誤的。請告訴我如何對模式進行編碼以驗證下面的文件XML。類型替換的XML模式
詳情:
- 只有兩種存儲一個類型的動物是鳥,一個是魚。
- 對於類型,名稱和原點元素都是必需的
- 對於類型:鳥類,可以選擇存儲其他顏色元素。
類型:魚,另外大小元素必須是店內
<animals> <animal animalID="b-1" xsi:type="bird"> <name>Humming Bird</name> <origin>Asia</origin> <color>Blue</color> </animal> <animal animalID="b-2" xsi:type="bird"> <name>Horn Bill</name> <origin>Asia</origin> </animal> <animal animalID="f-2" xsi:type="fish"> <name>Whale</name> <origin>Europe</origin> <size>Large</size> </animal> <animal animalID="b-5" xsi:type="bird"> <name>Parrot</name> <origin>Europe</origin> </animal>
我已經推出了以下的模式,我認爲它完全錯誤的。
<xsd:element name="bird" substitutionGroup="animals"
type="birdType"/>
<xsd:element name="fish" substitutionGroup="animals"
type="fishType"/>
<xsd:element name="animals">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="animal" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="animal">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bird" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
你好凱,你的意思是喜歡下面的代碼嗎? – setiasetia
是的,這就是主意。 –