xml XSD:默认整数值范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15486246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:56:11  来源:igfitidea点击:

XSD: default integer value range

xmlxsdxml-validation

提问by Jeff

Is there an implied default value range when defining an element of a specific data type in an XSD file? For example if I define an element of type integer:

在 XSD 文件中定义特定数据类型的元素时是否有隐含的默认值范围?例如,如果我定义一个整数类型的元素:

<xs:element name="MyIntegerElement" type="xs:integer"/>

Does this have an implied min and max value that it will validate to? I know I can explicitly define the valid ranges like so:

这是否有一个隐含的最小值和最大值来验证?我知道我可以像这样明确定义有效范围:

<xs:element name="MyIntegerElement">
   <xs:simpleType>
      <xs:restriction base="xs:integer">
         <xs:minInclusive value="1"/>
         <xs:maxInclusive value="16"/>
      </xs:restriction>
   </xs:simpleType>
</xs:element>

But if I don't do this when I validate an XML file against this will it default to a range of valid values? I've been digging around in the XSD documentation but haven't found the answer yet.

但是如果我在验证 XML 文件时不这样做,它会默认为一系列有效值吗?我一直在寻找 XSD 文档,但还没有找到答案。

采纳答案by Francisco Paulo

Well, it depends on the data type...

嗯,这取决于数据类型......

If you look at the definition of integerat w3:

如果您查看at w3定义integer

The value space of integer is the infinite set {...,-2,-1,0,1,2,...}

整数的值空间是无限集 {...,-2,-1,0,1,2,...}

In essence it means that, for integers, by default there is no min/max value range since any integer can be represented.

本质上,这意味着对于整数,默认情况下没有最小值/最大值范围,因为可以表示任何整数。

On the other hand, for an int:

另一方面,对于一个int

(...) maxInclusive to be 2147483647 and minInclusive to be -2147483648.

(...) maxInclusive 为 2147483647,minInclusive 为 -2147483648。

The list goes on for longs, shorts, etc...

这样的例子不胜枚举了longsshorts等...

You can read it in more detail here: http://www.w3.org/TR/xmlschema-2/#typesystem

您可以在此处更详细地阅读:http: //www.w3.org/TR/xmlschema-2/#typesystem