我有一个如下所示的 xml 输入,并想为其创建一个 XML 架构。但是我创建的架构似乎有问题。是否可以向我展示如何为下面的 xml 创建架构。
-ownerName in ownerDetail 元素对农场元素中的farmOwnerName 的引用
<Country>
<state>
<farm farmOwnerName="Jerry" produce="apple">
<established>1974</established>
<totalWorker>30</totalWorker>
</farm>
<farm farmOwnerName="Ronald" produce="apple" quality="best">
<established>1969</established>
<totalWorker>15</totalWorker>
</farm>
<farm farmOwnerName="Richard" produce="lemon">
<established>1970</established>
<totalWorker>20</totalWorker>
</farm>
</state>
<ownerDetail age="70" ownerName="Ronald">
<bornIn>Australia</bornIn>
</ownerDetail>
<ownerDetail age="50" ownerName="Richard">
<bornIn>Canada</bornIn>
</ownerDetail>
</Country>
我编码的架构如下:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="state" type="xs:string"/>
<xs:element name="established" type="xs:integer"/>
<xs:element name="totalWorker" type="xs:integer"/>
<xs:element name="bornIn" type="xs:string"/>
<xs:element name="Country">
<xs:complexType name="farm">
<xs:sequence maxOccurs="unbounded">
<xs:element ref="established"/>
<xs:element ref="totalWorker"/>
</xs:sequence>
<xs:attribute name="farmOwnerName" use="required"/>
<xs:attribute name="produce" use="required"/>
<xs:attribute name="quality" use="optional">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="best"/>
<xs:enumeration value="normal"/>
<xs:enumeration value="low"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="ownerDetail">
<xs:sequence maxOccurs="unbounded">
<xs:element ref="bornIn"/>
</xs:sequence>
<xs:attribute name="age" use="required"/>
<xs:attribute name="ownerName" use="required"/>
</xs:complexType>