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

标签 xml xsd specifications xsd-validation

我引用的是 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/

相关文章:

android - 通过代码获取另一个 XML 布局中的 XML 布局 [Android]

java - Android 布局(固定页眉 + 滚动部分 + 固定页脚)

java - Xpath 从同一节点选择多个属性

visual-studio-2010 - 如何修改我的设置以允许 VS2010 从 "Unauthorized Zone"加载第 3 方 XSD 文件?

java - 为什么使用 Schema 验证 XML 时未验证数据类型?

HTML5 兼容 - 类属性中的尾随空格

java - 通过JAVA解析xml的问题

regex - Xml 模式正则表达式不允许单独使用空格

bdd - 如何记录故事/功能中的非功能性需求 (NFR)?

java - Future.get(long, TimeUnit) 的负超时安全吗?