2013-02-04 34 views
4

我已經看到了如何在一個XSD中的元素聲明中直接使用的唯一的標籤的例子,但我無法弄清楚如何放入元素聲明這是一個複雜類型,請參見下面的代碼:如何在複雜類型的xsd文件中使用唯一標記?

<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,我可以得到下面的例子,但它直接在元素聲明中使用。

Example

謝謝!

回答

6

在XSD中,身份約束與元素關聯,而不是與類型關聯。因此,將模式中的元素定義爲類型flighttype,而不是flighttype本身,請定義該元素上的身份約束。

+0

謝謝你的建議,幫助我弄明白了! :) – deucalion0

相關問題