那些日子我正在尝试找到一种方法来创建一个全局属性,该属性将被架构中的所有元素使用,并将作为它们的关键/唯一属性。看下一个例子:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified" targetNamespace="http://www.NameSpace/Family" xmlns:tns="http://www.NameSpace/Family">
<xs:attribute name="id" type="xs:string"/>
<xs:complexType name="parentType">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Child" type="tns:childType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="tns:id" use="required"/>
</xs:complexType>
<xs:complexType name="childType">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
</xs:sequence>
<xs:attribute ref="tns:id" use="required"/>
</xs:complexType>
<xs:element name="Family">
<xs:complexType>
<xs:sequence>
<xs:element name="Parent" type="tns:parentType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
现在让我们说,例如,我创建了 1 个父母和 2 个孩子,我想在 id 属性上定义一个键/唯一,以便所有元素 id(父母和孩子)彼此不同。