微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml – 如何在复杂类型的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

谢谢!

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。