我引用的是 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.
总而言之,如果小数的小数部分为零,则词法表示允许没有小数点和尾随零,而规范表示明确指出小数是必需的。
以下哪个定义是“正确的”?我的应用程序正在发送词法表示,而消费应用程序需要规范表示。
最佳答案
XSD 中的有效性是根据词法表示定义的,而不是规范表示,因此根据 XSD 严格给出的任何契约(Contract),您的应用程序完全有权要求 xs:decimal
排除没有小数部分的小数点。
XSD 中不使用规范表示,但提供了一种标准方法来将数据类型序列化为其他 W3C 推荐标准,例如 XPath/XQuery。
关于xml - XSD 规范中词汇表示与规范表示之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32618556/