I want to define a smaple XML Schema for a social network website.I've defined a Person element and it's related attributes and other child elements.it's a part of the schema which I've defined. :
我想为社交网络网站定义一个简单的XML Schema。我已经定义了一个Person元素及其相关属性和其他子元素。它是我定义的模式的一部分。 :
<xs:element name="Person" type="Person" />
<xs:complexType name="Person">
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name="nickName" type="xs:string"/>
<xs:element name="age" >
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="birthDate" type="xs:date"/>
<xs:element name="gender" type="Gender" />
<xs:element name="contactDetails" type="ContactInfo"/>
<xs:element name="occupation" type="Occupation" />
</xs:sequence>
</xs:complexType>
now I want to define another child for Person as it's friends but I dont know how can I do this.does any body have any Idea about this?
现在我想为Person定义另一个孩子,因为它是朋友,但我不知道我怎么能这样做。任何人都有任何想法吗?
1 个解决方案
#1
4
Does this work for you:
这对你有用吗:
<xs:element name="Persons">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="PersonType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="uniquePersonId">
<xs:selector xpath="./Persons"/>
<xs:field xpath="@PersonID"/>
</xs:unique>
</xs:element>
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name = "Friends" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Friend" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:attribute name="FriendId" type="xs:IDREF" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="PersonID" type="xs:ID" use="required"/>
</xs:complexType>
#1
4
Does this work for you:
这对你有用吗:
<xs:element name="Persons">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="PersonType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="uniquePersonId">
<xs:selector xpath="./Persons"/>
<xs:field xpath="@PersonID"/>
</xs:unique>
</xs:element>
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name = "Friends" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Friend" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:attribute name="FriendId" type="xs:IDREF" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="PersonID" type="xs:ID" use="required"/>
</xs:complexType>