2015-05-11 38 views
0

是否可以將complexType的子項限制爲存在於另一個complexType子元素中。xsd將孩子限制爲另一個複雜類型的子項

例如

<xs:element name="people"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="person" type="personType" maxOccurs="unbounded" /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 

<xs:element name="companies"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="company" type="companyType" maxOccurs="unbounded" /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 

而現在我想有應限制在人們元素存在上述員工companyType。

+2

通常,它是通過'ID' /'IDREFS'執行的,以避免重複信息。 – potame

+0

耶謝謝你。我現在使用key和keyref。 – KooKoo

+0

那麼你現在在做什麼key/keyref不適合你? – kjhughes

回答

1

非常感謝potame。正如kjhughes aksed我現在所做的,我會在這裏發佈。

嗯,我已經創建了公司名稱和推薦人的關鍵。

<xs:key name="CompanyKey" > 
    <xs:selector xpath="./companies/company" /> 
    <xs:field xpath="name" /> 
</xs:key> 
<xs:keyref name="CompanyKeyRef" refer="CompanyKey"> 
    <xs:selector xpath="./people/person" /> 
    <xs:field xpath="@company_name" /> 
</xs:keyref> 

我只是將這些放在我的根元素中的xsd文件。

現在它就像一個數據庫。公司的名稱是關鍵,人的公司名稱是外鍵。所以公司和人之間有很多關係。

+0

這是您的問題的答案或添加到其中的其他信息? – kjhughes

+0

這是答案 – KooKoo

相關問題