xsd 将子项限制为另一个 complexType 的子项
xsd restrict children to children of another complexType
是否可以限制一个 complexType 的子项存在于另一个 complexType 的子项中。
例如
<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 中,我希望员工应该限制在上面的 people 元素中存在。
好吧,多亏了 potame。当 kjhughes 问我现在做什么时,我将 post 放在这里。
好吧,我已经为公司名称创建了一个键,为个人创建了一个推荐人。
<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 文件的根元素中。
现在它就像一个数据库。公司名称是键,人的 company_name 是外键。所以公司和人之间有很多关系。
是否可以限制一个 complexType 的子项存在于另一个 complexType 的子项中。
例如
<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 中,我希望员工应该限制在上面的 people 元素中存在。
好吧,多亏了 potame。当 kjhughes 问我现在做什么时,我将 post 放在这里。
好吧,我已经为公司名称创建了一个键,为个人创建了一个推荐人。
<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 文件的根元素中。
现在它就像一个数据库。公司名称是键,人的 company_name 是外键。所以公司和人之间有很多关系。