我对 xml 很陌生,所以请原谅我的愚蠢问题。好吧,我有这样的架构
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Product">
<xs:complexType>
<xs:sequence>
<xs:element name= "name" type = "xs:string"/>
<xs:element name= "price" type = "xs:decimal"/>
<xs:element name= "Fish">
<xs:complexType>
<xs:sequence>
<xs:element name= "Type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="herbivourus"/>
<xs:enumeration value="predator"/>
<xs:enumeration value="detritophages"/>
<xs:enumeration value="omnivourus"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Clown">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="Character" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Slow"/>
<xs:enumeration value="Quiet"/>
<xs:enumeration value="Fearful"/>
<xs:enumeration value="Motile"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Agressiveness">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="HIGH"/>
<xs:enumeration value="MEDIUM"/>
<xs:enumeration value="LOW"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="gotSpikes" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Lionfish">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="gotSpikes" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Triggerfish">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="needsHideout" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Trumpetfish">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="gregarious" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Yellow_boxfish">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="gregarious" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="reptile">
<xs:complexType>
<xs:sequence>
<xs:element name="compatibleWithFish" type= "xs:boolean"/>
<xs:element name="needsLand" type= "xs:boolean"/>
<xs:element name="turtle">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="gregarious" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="decoration">
<xs:complexType>
<xs:sequence>
<xs:element name="size" type= "xs:int"/>
<xs:element name="alga">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="doesGetsOxygen" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="castle">
<xs:complexType>
<xs:sequence>
<xs:element name="serialVersionUID" type="xs:long"/>
<xs:element name="isHideOut" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
实际上有我的xml
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="tank.xsd">
<Product>
<<Fish>
<Clown name = "Clown">
<serialVersionUID>
-7114819146190513293L
</serialVersionUID>
<Character>QUIET</Character>
<Aggressiveness>LOW</Aggressiveness>
<gotSpikes>false</gotSpikes>
<type> herbivourus</type>
<price> 51000 </price>
</Clown>
<Lionfish>
<serialVersionUID>
5302423581237004299L
</serialVersionUID>
<price>25000</price>
<name> Lionfish </name>
<type> herbivourus</type>
<gotSpikes>true</gotSpikes>
</Lionfish>
<Triggerfish>
<serialVersionUID>
4102072582518577014L
</serialVersionUID>
<price>27000</price>
<name> Triggerfish </name>
<type> herbivourus</type>
<needsHideout>true</needsHideout>
</Triggerfish>
<Trumpetfish>
<serialVersionUID>
-6802935171639886135L
</serialVersionUID>
<price>34500</price>
<name> Trumpetfish </name>
<type> herbivourus</type>
<gregarious> true</gregarious>
</Trumpetfish>
<Yellow_boxfish>
<serialVersionUID>
4377441012026861992L
</serialVersionUID>
<price>56900</price>
<name> Yellow_boxfish </name>
<type> herbivourus</type>
<gregarious> true</gregarious>
</Yellow_boxfish>
</Fish>
<Reptile>
<Turtle>
<serialVersionUID>
-3606085842515781016L
</serialVersionUID>
<price>129000</price>
<name> Turtle </name>
<compatibleWithFish> true</compatibleWithFish>
<needsLand>true</needsLand>
<gregarious> true </gregarious>
</Turtle>
</Reptile>
<Decoration>
<Alga>
<serialVersionUID>
-4311096533955485410L
</serialVersionUID>
<price>15000</price>
<name> alga </name>
<doesGetOxygen> true</doesGetOxygen>
</Alga>
<Castle>
<serialVersionUID>
1L
</serialVersionUID>
<price>110300</price>
<name> Castle </name>
<ishideout> true</ishideout>
</Castle>
</Decoration>
</Product>
顺便说一句,我有这样一个类层次结构
- 抽象产品
- 抽象的鱼
- 小丑
- 狮子鱼
- 扳机鱼
- 喇叭鱼
- Yellow_boxfish
- 抽象爬行动物
- 龟
- 抽象装饰
- 藻类
- Calstle 验证器的输出是“根元素之前的文档中的标记必须格式正确”所以请指点我有什么问题
- 抽象的鱼
PS我需要在xsd中显示类的层次结构,并且基类是产品类,所有子类都将有一个字段名称和价格,所以我不确定它是否在我的模式中正确显示:C和顺便说一句我将实例化这些类