xsd:key和xsd:unique之间的区别

时间:2022-05-03 22:31:10

What is the difference between using xsd:unique and xsd:key?

使用xsd:unique和xsd:key有什么区别?

5 个解决方案

#1


11  

xsd:unique does not require the field to exist for the selector. If the field exists, its value should be unique.

xsd:unique不需要为选择器存在该字段。如果该字段存在,则其值应该是唯一的。

xsd:key requires the field to exist for all selector results. Every element in the selector should have a key.

xsd:key要求所有选择器结果都存在该字段。选择器中的每个元素都应该有一个键。

Note that xsd:keyref is not a requirement for xsd:key, the xsd:key can be there withoug any xsd:keyref.

请注意,xsd:keyref不是xsd:key的要求,xsd:key可以与任何xsd:keyref一起使用。

#2


5  

I found my own answer:

我找到了自己的答案:

It all has to do with cardinality:

这一切都与基数有关:

xsd:key is used for (0..N) and (1..1) multiplicity. xsd:unique is used for optional (0..1) multiplicity. This is also the reason why a the selected field in a xsd:unique can be nill.

xsd:key用于(0..N)和(1..1)多重性。 xsd:unique用于可选(0..1)多重性。这也是为什么xsd:unique中的选定字段可以是nill的原因。

Source of my answer: http://www.xml.com/lpt/a/987

我的回答来源:http://www.xml.com/lpt/a/987

#3


1  

it is similar to database.

它类似于数据库。

key field is like primarykey.. unique and id

关键字段就像primarykey .. unique和id

unique field is not a key but it has to be unique...

独特的领域不是关键,但它必须是独一无二的......

#4


1  

See http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/primer.html#quartelyReport.

见http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/primer.html#quartelyReport。

In the example described in the link the "keyRefed" elements are the values of the number attributes of the parts of the zip of the regions and the "keyed" elements are the values of the number attribute of the part of the parts.

在链接中描述的示例中,“keyRefed”元素是区域的zip部分的数字属性的值,并且“键控”元素是部分部分的数字属性的值。

Unique declares that the values must be unique but can be null also, key - that they must be unique. Both types can be references by "keyRefed" elements.

Unique声明值必须是唯一的,但也可以为null,key - 它们必须是唯一的。两种类型都可以通过“keyRefed”元素引用。

#5


0  

xsd:key is unique AND is used for a collection of elements a key within a scope xsd:unique is just unique within a scope.

xsd:key是唯一的AND用于范围xsd中的键的元素集合:unique在范围内是唯一的。

Hope this helps...

希望这可以帮助...

#1


11  

xsd:unique does not require the field to exist for the selector. If the field exists, its value should be unique.

xsd:unique不需要为选择器存在该字段。如果该字段存在,则其值应该是唯一的。

xsd:key requires the field to exist for all selector results. Every element in the selector should have a key.

xsd:key要求所有选择器结果都存在该字段。选择器中的每个元素都应该有一个键。

Note that xsd:keyref is not a requirement for xsd:key, the xsd:key can be there withoug any xsd:keyref.

请注意,xsd:keyref不是xsd:key的要求,xsd:key可以与任何xsd:keyref一起使用。

#2


5  

I found my own answer:

我找到了自己的答案:

It all has to do with cardinality:

这一切都与基数有关:

xsd:key is used for (0..N) and (1..1) multiplicity. xsd:unique is used for optional (0..1) multiplicity. This is also the reason why a the selected field in a xsd:unique can be nill.

xsd:key用于(0..N)和(1..1)多重性。 xsd:unique用于可选(0..1)多重性。这也是为什么xsd:unique中的选定字段可以是nill的原因。

Source of my answer: http://www.xml.com/lpt/a/987

我的回答来源:http://www.xml.com/lpt/a/987

#3


1  

it is similar to database.

它类似于数据库。

key field is like primarykey.. unique and id

关键字段就像primarykey .. unique和id

unique field is not a key but it has to be unique...

独特的领域不是关键,但它必须是独一无二的......

#4


1  

See http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/primer.html#quartelyReport.

见http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/primer.html#quartelyReport。

In the example described in the link the "keyRefed" elements are the values of the number attributes of the parts of the zip of the regions and the "keyed" elements are the values of the number attribute of the part of the parts.

在链接中描述的示例中,“keyRefed”元素是区域的zip部分的数字属性的值,并且“键控”元素是部分部分的数字属性的值。

Unique declares that the values must be unique but can be null also, key - that they must be unique. Both types can be references by "keyRefed" elements.

Unique声明值必须是唯一的,但也可以为null,key - 它们必须是唯一的。两种类型都可以通过“keyRefed”元素引用。

#5


0  

xsd:key is unique AND is used for a collection of elements a key within a scope xsd:unique is just unique within a scope.

xsd:key是唯一的AND用于范围xsd中的键的元素集合:unique在范围内是唯一的。

Hope this helps...

希望这可以帮助...