我需要像这样指定一个 XML 片段:
<address type="work">...</address>
<address type="home">...</address>
地址是必需的work,但home地址是可选的。如何在 XML Schema 中实现该限制?
这是我的address复杂类型:
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="street" type="xs:string"></xs:element>
<xs:element name="postalCode" type="PostalCodeType"></xs:element>
<xs:element name="town" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="work" />
<xs:enumeration value="home" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
我列出了address这样的元素:
<xs:element name="address" type="AddressType"></xs:element>
<xs:element name="address" type="AddressType" minOccurs="0"></xs:element>
那么,我如何指定第一个是专门的type="work"地址,而另一个是type="home"地址呢?