我正在创建 XML Schema,我的一个值是一年.因此,我想确保所有值都有4个字符.为此,我使用以下语法: xs:element name="publish_year" maxOccurs="1" xs:simpleType xs:restriction base="xs:positiveInteger" xs:totalDig
<xs:element name="publish_year" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:totalDigits value="4"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
如果我正确理解“totalDigits”,有人可以传入“publish_year”值“2008”或“200”.两者都有效.因此,如何构建我的XSD以确保需要4位数?乍一看,我猜我会使用正则表达式,但我想知道我是否忽略了已经出现过的东西(比如“totalDigits”)
更新:
我选择了以下解决方案.它可能有点矫枉过正,但它得到了重点:
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:totalDigits value="4" fixed="true"/>
<xs:minInclusive value="1900"/>
<xs:pattern value="^([1][9]\d\d|[2]\d\d\d)$"/>
</xs:restriction>
</xs:simpleType>
如果将价值作为附加限制呢?
(minInclusive – maxInclusive)
例如 ?
<xs:minInclusive value="1900"/> et <xs:maxInclusive value="2008"/>
但是为了回到totalDigits约束,为什么不将fixed属性设置为true?
If {fixed} is true, then types for which the current type is the {base type definition} cannot specify a value for totalDigits other than {value}.
<xs:totalDigits value="4" fixed="true" />
