是否可以将xsd:enumeration标记设为必需/必需? [英] Can an xsd:enumeration tag be made mandatory/required?

查看:93
本文介绍了是否可以将xsd:enumeration标记设为必需/必需?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短形式的问题:xsd:enumeration标签是否可以具有必填属性,如在使用此枚举的任何标签中必须至少使用一次特定的枚举值?

Short-form question: Can an xsd:enumeration tag have a required attribute, as in any tag that uses this enumeration MUST use the specific enumeration value at least once?

详细信息:例如,假设我已经在我的xsd中定义了fruit xml标签。水果标签具有一个属性,其值为枚举FruitType。定义如下:

Details: For example, let's say that I have already defined a fruit xml tag in my xsd. The fruit tag has an attribute whose value is the enumeration FruitType. It is define as such:

<xsd:simpleType name="FruitType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Apple" />
<xsd:enumeration value="Banana" />
<xsd:enumeration value="Peach" />
<xsd:enumeration value="Orange" />
</xsd:restriction>
</xsd:simpleType>

我想使Apple枚举值达到要求,以便用户必须至少具有一个带有属性苹果。是否可以在xsd枚举中使用这样的标签?我认为也许我们可以在xsd:enumeration标记中放入use = required或minOccurs = 1。

I want to make the Apple enumeration value required such that the user must have at least one fruit tag with the attribute Apple. Is it possible to use such a tag in xsd enumeration? I thought that maybe we can put use="required" or minOccurs="1" in the xsd:enumeration tag. Please let me know.

谢谢!

推荐答案

做什么您的意思是用户必须至少具有一个带有Apple属性的水果标签。您是说要使该文档有效,此值必须出现在每个实例文档中的某个位置吗?还是在更狭窄的范围内(例如,在FruitBasket元素内)?在这两种情况下,这都不是枚举类型的属性,而是对有问题的元素或文档的约束。

What do you mean by "the user must have at least one fruit tag with the attribute Apple". Do you mean this value must appear somewhere in each instance document if the document is to be valid? Or within some narrower scope (say within a FruitBasket element)? In both cases, that's not a property of the enumeration type, it's a constraint on the element or document in question.

我认为没有任何办法可以做到这一点在XSD 1.0中。在XSD 1.1中,像大多数事情一样,可以使用断言来完成。例如,

I don't think there's any way of doing this in XSD 1.0. In XSD 1.1, like most things, it can be done with assertions. For example

<xs:element name="FruitBasket">
  ...
  <xs:assert test=".//Fruit = 'Apple'"/>
</xs:element>

XSD 1.1当前在Xerces和Saxon中实现。

XSD 1.1 is currently implemented in Xerces and Saxon.

这篇关于是否可以将xsd:enumeration标记设为必需/必需?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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