XSD 规范中词汇表示与规范表示之间的区别

Difference between lexical vs canonical representation in XSD spec

我今天引用 XSD spec 查找小数类型的定义。在其中,我发现了两个不同的数据类型冲突定义,一个词法定义和一个规范定义,引用如下:

3.2.3.1 Lexical representation

decimal has a lexical representation consisting of a finite-length sequence of decimal digits (#x30-#x39) separated by a period as a decimal indicator. An optional leading sign is allowed. If the sign is omitted, "+" is assumed. Leading and trailing zeroes are optional. If the fractional part is zero, the period and following zero(es) can be omitted. For example: -1.23, 12678967.543233, +100000.00, 210.

3.2.3.2 Canonical representation

The canonical representation for decimal is defined by prohibiting certain options from the Lexical representation (§3.2.3.1). Specifically, the preceding optional "+" sign is prohibited. The decimal point is required. Leading and trailing zeroes are prohibited subject to the following: there must be at least one digit to the right and to the left of the decimal point which may be a zero.

总而言之,如果小数的小数部分为零,则词法表示允许没有小数点和尾随零,而规范表示明确指出小数是必需的。

以下哪个定义是 "correct"?我的应用程序正在发送词法表示,而消费应用程序需要规范表示。

XSD 中的有效性是针对词汇表示而不是规范表示定义的,因此根据 XSD 要求 xs:decimal 在没有小数部分的情况下排除小数点。

规范表示未在 XSD 中使用,但提供了一种标准方法来将数据类型序列化为其他 W3C 建议,例如 XPath/XQuery。