Xml 如何在复杂类型中使用xsd文件中的唯一标记?

Xml 如何在复杂类型中使用xsd文件中的唯一标记?,xml,xsd,uniqueidentifier,Xml,Xsd,Uniqueidentifier,我已经看到了如何在xsd中的元素声明中直接使用unique标记的示例,但我不知道如何将其放入complextype元素声明中,请参见下面的代码: <xs:complexType name="flighttype"> <xs:sequence> <xs:element name="departure" type="departuretype"/> <xs:element name="arrival" type="arrivaltype"/&

我已经看到了如何在xsd中的元素声明中直接使用unique标记的示例,但我不知道如何将其放入complextype元素声明中,请参见下面的代码:

<xs:complexType name="flighttype">
<xs:sequence>
    <xs:element name="departure" type="departuretype"/>
    <xs:element name="arrival" type="arrivaltype"/>
    <xs:element name="altitude" type="xs:string"/>
    <xs:element name="speed" type="xs:string"/>
    <xs:element name="distance" type="xs:string"/>
    <xs:element name="entertainment" type="entertainmenttype"/>
    <xs:element name="safetymessage" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
<xs:attribute name="airline" type="xs:string"/>
<xs:attribute name="flightno" type="xs:string"/>
<xs:attribute name="model" type="xs:string"/>
<xs:attribute name="passengers" type="xs:integer"/>
<xs:attribute name="status" type="xs:string"/>
</xs:complexType>

我想让这个id成为一个唯一的id,我可以让下面的示例工作,但它直接在元素声明中使用


谢谢大家!

在XSD中,标识约束与元素关联,而不是与类型关联。因此,在模式中定义为具有类型
flighttype
的元素上定义标识约束,而不是在
flighttype
本身上定义标识约束