具有包含空格的 xsd:token-type 元素的实例会通过验证吗? [英] Will an instance with a xsd:token-type element containing whitespace pass validation?

查看:20
本文介绍了具有包含空格的 xsd:token-type 元素的实例会通过验证吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最终目标是通过简单地不允许不良 xs:token 内容通过相关元素的模式验证来防止经过验证的 XML 内容池中出现空白.模式无效的实例不允许进入池.

The ultimate goal is to prevent whitespace in a pool of validated XML content by simply not allowing bad xs:token content to pass schema validation for relevant elements. Schema-invalid instances are not allowed into the pool.

如果我在 XML 模式 (1.1) 中将元素的类型声明为 xsd:token 并且我尝试验证此模式的实例,其中 xsd:token-typed 元素包含超过零个被拒绝的字符(制表符、LF、CR)或双、前导或尾随空格,该实例是否验证?

If I declare an element's type to be xsd:token in an XML Schema (1.1) and I try to validate an instance of this schema where the xsd:token-typed element contains more than zero of the repudiated characters (tab, LF, CR) or a double, leading or trailing space, will said instance validate or not?

假设:内容没有其他限制"(可以这么说),只是它必须是 xsd:token.

Assume: there's no other "restriction" (so to speak) on the content, only that it has to be an xsd:token.

扩展只是为了完全清楚:设置 xs:whiteSpace=collapse 意味着前导和尾随空格被删除,内部空格被减少为单个 x20 字符" - 我知道这是一个预验证/内部" (可以这么说) XML 验证器的步骤;是吗?

Extension just to be totally clear: "The setting xs:whiteSpace=collapse means that leading and trailing whitespace is removed and internal whitespace is reduced to a single x20 character" - I understand that this is a "pre-validation / internal" (so to speak) step for the XML validator; is that right?

推荐答案

您的问题通过谈论空格限制"揭示了一个不正确的假设.xs:whiteSpace 方面没有定义限制,它定义了规范化:即.在应用验证之前空白会发生什么.在大多数情况下,空白被折叠,这意味着前导和尾随空白被删除,并且内部空白被减少为单个空格字符.如果存在模式方面,则它适用于完成此空白规范化后的值.

Your question reveals an incorrect assumption by talking of whitespace "restrictions". The xs:whiteSpace facet does not define restrictions, it define normalizations: ie. what happens to whitespace before validation is applied. In most cases whitespace is collapsed, which means that leading and trailing whitespace is removed, and internal whitespace is reduced to a single space character. If there is a pattern facet then it applies to the value after this whitespace normalization has been done.

对于 xs:token,请注意该类型的名称具有高度误导性.xs:token 的实例可以包含空格.设置 xs:whiteSpace=collapse 意味着删除前导和尾随空格,并将内部空格减少为单个 x20 字符;结果将始终是 xs:token 的有效实例.

For xs:token, note that the name of the type is highly misleading. An instance of xs:token can contain whitespace. The setting xs:whiteSpace=collapse means that leading and trailing whitespace is removed and internal whitespace is reduced to a single x20 character; the result will always be a valid instance of xs:token.

(当然,只有在处理验证后信息集时才对验证后的规范化值感兴趣,例如通过使用模式感知 XSLT 或 XQuery.如果您只是进行验证以获取无效的错误,那么 xs:token 和 xs:string 是完全等价的.)

(Of course, the normalized value after validation is of interest only if you are processing the post-validation infoset, for example by using schema-aware XSLT or XQuery. If you are only doing validation to get an error if it's invalid, then xs:token and xs:string are completely equivalent.)

这篇关于具有包含空格的 xsd:token-type 元素的实例会通过验证吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆