XSD 中元素的 ref 属性有什么作用? [英] What does the ref attribute on an element in an XSD do?

查看:73
本文介绍了XSD 中元素的 ref 属性有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档似乎说它引用了架构中的另一个元素,但如何使用它 - 我从未在我使用过的架构中看到它.

Documentation seems to say that it references another element in the schema, but how could it be used - I've never seen it in schemas that I have worked with.

有人有什么好的用例或可以进一步解释其用途的东西吗?

Anyone got any nice use cases or something that could explain its use further?

推荐答案

基本上它引用了在别处声明的另一个元素,它可能是也可能不是同一个架构文档.

Basically it references another element that is declared elsewhere, which may or may not be the same schema document.

例如,它可能来自不同命名空间中的外部引用架构.假设您在几个不同的模式中多次使用 item 元素,您可以在一个 common 模式中声明它(以及任何其他常见的类型和属性),然后在所有其他架构.

For instance, it could come from an externally referenced schema in a different namespace. Suppose you use the item element a lot in several different schemas, you can declare it (and any other common types and attributes) in a common schema, and then reuse those in all your other schemas.

如果您使用命名空间 c 引用您的 common 架构,则可以单独或作为一部分声明 item 元素的实例类型如下:

If you reference your common schema with the namespace c, you can declare an instance of the item element on its own or as part of a type as follows:

<xs:element ref="c:item" /><!-- reference here -->
<xs:complexType name="something">
    <xs:sequence>
        <xs:element ref="c:item" /><!-- and here -->
    </xs:sequence>
    <xs:element name="other" type="xs:Name" />
</xs:complexType>

数据模式中的定义如下所示:

The definition in the data schema would look like this:

<xs:element name="item" type="itemType" /><!-- referenced element -->
<xs:complexType name="itemType">
    <xs:sequence>
        <xs:element name="code" type="xs:Name" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="description" type="xs:normalizedString" use="required" />
</xs:complexType>

这篇关于XSD 中元素的 ref 属性有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆