大家我有一个小问题我想要一个属性来充当member_id。
这是因为如果我将它作为另一个标签,我不能让它完全独一无二,我只能让它对所有 full_member 类型和 basic_member 类型都是唯一的。
所以我想我可以用一个属性和一个键来解决这个问题。
但我的问题是我不能拥有相邻的属性和选择,或者我只是不知道如何正确地做。
到目前为止,以下是我的架构。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="memberinfo">
<xs:sequence>
<xs:element ref="member_id"/>
<xs:element ref="first_name"/>
<xs:element ref="last_name"/>
<xs:element ref="address"/>
<xs:element ref="contact_numbers"/>
<xs:element ref="date_joined"/>
</xs:sequence>
</xs:complexType>
<xs:element name="member_id" type="xs:integer"/>
<xs:element name="first_name" type="xs:NCName"/>
<xs:element name="last_name" type="xs:NCName"/>
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element ref="house_number"/>
<xs:element ref="house_name"/>
</xs:choice>
<xs:element ref="street"/>
<xs:element ref="town"/>
<xs:element ref="city"/>
<xs:element ref="county"/>
<xs:element ref="postcode"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="house_number" type="xs:integer"/>
<xs:element name="house_name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="town" type="xs:NCName"/>
<xs:element name="city" type="xs:NCName"/>
<xs:element name="county" type="xs:NCName"/>
<xs:element name="postcode" type="xs:NCName"/>
<xs:element name="contact_numbers">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="3" ref="contact_number"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="contact_number" type="xs:integer"/>
<xs:element name="date_joined" type="xs:date"/>
<xs:complexType name="basic_member">
<xs:complexContent>
<xs:extension base="memberinfo">
<xs:sequence>
<xs:element name="activities">
<xs:complexType>
<xs:sequence>
<xs:element name="activity_name" maxOccurs="3"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="full_member">
<xs:complexContent>
<xs:extension base="memberinfo">
<xs:sequence>
<xs:element name="activities">
<xs:complexType>
<xs:sequence>
<xs:element name="activity_name" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="members" >
<xs:complexType>
<xs:sequence>
<xs:element name="member" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="member_id"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="PK_member">
<xs:selector xpath=".//member" />
<xs:field xpath="member_id" />
</xs:key>
</xs:element>
</xs:schema>
输入示例
<member>
<full_member>
<member_id>1</member_id>
<first_name>Simon</first_name>
<last_name>Hughes</last_name>
<address>
<house_number>12</house_number>
<street>Ashgrove Road</street>
<town>Forest Town</town>
<city>Mansfield</city>
<county>Nottinghamshire</county>
<postcode>NG385DX</postcode>
</address>
<contact_numbers>
<contact_number>01623948594</contact_number>
<contact_number>01623349596</contact_number>
<contact_number>01623486599</contact_number>
</contact_numbers>
<date_joined>2012-05-21</date_joined>
<activities>
<activity_name>Treadmill</activity_name>
<activity_name>Squash</activity_name>
<activity_name>Table Tennis</activity_name>
<activity_name>Weights</activity_name>
</activities>
</full_member>
</member>
<member>
<full_member>
<member_id>2</member_id>
<first_name>Scott</first_name>
<last_name>Calladine</last_name>
<address>
<house_name>Don House</house_name>
<street>Simons Road</street>
<town>Broadton</town>
<city>Supper</city>
<county>Nottinghamshire</county>
<postcode>N496DX</postcode>
</address>
<contact_numbers>
<contact_number>01623395865</contact_number>
<contact_number>01623496959</contact_number>
<contact_number>01623005604</contact_number>
</contact_numbers>
<date_joined>2007-08-16</date_joined>
<activities>
<activity_name>Static Cycle</activity_name>
<activity_name>Badminton</activity_name>
<activity_name>Table Tennis</activity_name>
</activities>
</full_member>
</member>
<member>
<full_member>
<member_id>3</member_id>
<first_name>Fransis</first_name>
<last_name>Smith</last_name>
<address>
<house_name>Don House</house_name>
<street>Lemington Close</street>
<town>Bradford</town>
<city>Bradfordcity>
<county>West Yorkshire</county>
<postcode>BD723DX</postcode>
</address>
<contact_numbers>
<contact_number>01623497035</contact_number>
<contact_number>01623389468</contact_number>
<contact_number>01623439949</contact_number>
</contact_numbers>
<date_joined>2007-08-16</date_joined>
<activities>
<activity_name>Static Cycle</activity_name>
<activity_name>Badminton</activity_name>
<activity_name>Table Tennis</activity_name>
</activities>
</full_member>
</member>
<member>
<full_member>
<member_id>4</member_id>
<first_name>Hayley</first_name>
<last_name>Cummingham</last_name>
<address>
<house_number>87</house_number>
<street>Boreast Road</street>
<town>Braranger</town>
<city>Mansfield</city>
<county>Nottinghamshire</county>
<postcode>N454HX</postcode>
</address>
<contact_numbers>
<contact_number>01623306031</contact_number>
<contact_number>01623206940</contact_number>
<contact_number>01623059680</contact_number>
</contact_numbers>
<date_joined>2012-05-21</date_joined>
<activities>
<activity_name>Treadmill</activity_name>
<activity_name>Squash</activity_name>
<activity_name>Table Tennis</activity_name>
<activity_name>Weights</activity_name>
</activities>
</full_member>
</member>
但使用我当前的模式,id 会变为 1 ,1 ,2 ,2
谢谢你