xsd 类型的 'anyURI' 可以包含空格吗?
Can xsd type of 'anyURI' contain spaces?
anyURI 类型的 XML 元素包含空格是否有效?
模式说是,但表示非常不鼓励。
http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#anyURI
NOTE: Spaces are, in principle, allowed in the ·lexical space· of anyURI, however, their use is highly discouraged (unless they are encoded by %20).
第三方正在为此 Audience 设置非转义空格,例如"Website One"。但这看起来很奇怪,请有人确认我没有发疯:)
更新
我应该提到我指的是 SAML2 断言模式中的受众元素,它只是将其声明为 anyUri,但如果它同样可以是一个字符串 ("one two three") 为什么它甚至被设置为 anyUri。
不确定,但你可能不会生气,至少不会因为这个原因。
尽管 anyURI 中允许使用空格,但包含它们将是非常愚蠢的,因为根据 RFC 3986.[=,它们不允许出现在 URI 引用中12=]
但是,在 XML 模式规范中,就在您引用的注释之前,还有这段话:
The ·lexical space· of anyURI is finite-length character sequences which, when the algorithm defined in Section 5.4 of [XML Linking Language] is applied to them, result in strings which are legal URIs according to [RFC 2396], as amended by [RFC 2732].
引用的算法指定在解析派生自 anyURI 元素的 URI 引用之前,您应该转义“非法”字符。
RFC 2396(早于 3986,在生成 XML 模式时是最新的)谈论使用白色 space 字符 "to delimit URI in many contexts".
因此我们可以假设字符串 "http://example.net/"
和 " http://example.net/ "
都是同一 URI 的表示。也就是说,它们在 value space 在 XML Schema 术语中占据相同的点,但在 lexical space 方面不同.
这也可能会引起头痛,所以最好不要使用 spaces。
第一点:xs:anyURI数据类型的whiteSpace facet被定义为"collapse",这意味着前导和尾随白色space字符被忽略,白色的内部序列space 相当于单个 space 字符。
第二点:正如@forty-two所述,如果你可以通过应用百分号编码得到一个合法的URI,那么它就是xs:anyURI
的一个合法的(XSD 1.0)实例:具体来说, "website one"
是相对 URI "website%20one"
.
的合法表示
(我喜欢用术语 "wannabe URI" 来描述一个字符串,它不是 URI,但在你应用转义后变成了 URI。XSD 1.0 允许想要的 URI。其中之一这里的主要困难是您不知道 URI 是否已经转义;如果您应用转义两次,您会得到 "website%2520one"
,这会让您陷入混乱。)
最后,在 XSD 1.1 中,所有赌注都取消了:"The value space of anyURI is the set of finite-length sequences of zero or more characters (as defined in [XML]) that ·match· the Char production from [XML]."。从本质上讲,考虑到 URI/IRI/LEIRI 规范的多样性,关于究竟什么是合法的,什么不是合法的争论太多了,以至于模式组决定,就有效性而言,任何事情都可以。
anyURI 类型的 XML 元素包含空格是否有效?
模式说是,但表示非常不鼓励。
http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#anyURI
NOTE: Spaces are, in principle, allowed in the ·lexical space· of anyURI, however, their use is highly discouraged (unless they are encoded by %20).
第三方正在为此 Audience 设置非转义空格,例如"Website One"。但这看起来很奇怪,请有人确认我没有发疯:)
更新
我应该提到我指的是 SAML2 断言模式中的受众元素,它只是将其声明为 anyUri,但如果它同样可以是一个字符串 ("one two three") 为什么它甚至被设置为 anyUri。
不确定,但你可能不会生气,至少不会因为这个原因。
尽管 anyURI 中允许使用空格,但包含它们将是非常愚蠢的,因为根据 RFC 3986.[=,它们不允许出现在 URI 引用中12=]
但是,在 XML 模式规范中,就在您引用的注释之前,还有这段话:
The ·lexical space· of anyURI is finite-length character sequences which, when the algorithm defined in Section 5.4 of [XML Linking Language] is applied to them, result in strings which are legal URIs according to [RFC 2396], as amended by [RFC 2732].
引用的算法指定在解析派生自 anyURI 元素的 URI 引用之前,您应该转义“非法”字符。
RFC 2396(早于 3986,在生成 XML 模式时是最新的)谈论使用白色 space 字符 "to delimit URI in many contexts".
因此我们可以假设字符串 "http://example.net/"
和 " http://example.net/ "
都是同一 URI 的表示。也就是说,它们在 value space 在 XML Schema 术语中占据相同的点,但在 lexical space 方面不同.
这也可能会引起头痛,所以最好不要使用 spaces。
第一点:xs:anyURI数据类型的whiteSpace facet被定义为"collapse",这意味着前导和尾随白色space字符被忽略,白色的内部序列space 相当于单个 space 字符。
第二点:正如@forty-two所述,如果你可以通过应用百分号编码得到一个合法的URI,那么它就是xs:anyURI
的一个合法的(XSD 1.0)实例:具体来说, "website one"
是相对 URI "website%20one"
.
(我喜欢用术语 "wannabe URI" 来描述一个字符串,它不是 URI,但在你应用转义后变成了 URI。XSD 1.0 允许想要的 URI。其中之一这里的主要困难是您不知道 URI 是否已经转义;如果您应用转义两次,您会得到 "website%2520one"
,这会让您陷入混乱。)
最后,在 XSD 1.1 中,所有赌注都取消了:"The value space of anyURI is the set of finite-length sequences of zero or more characters (as defined in [XML]) that ·match· the Char production from [XML]."。从本质上讲,考虑到 URI/IRI/LEIRI 规范的多样性,关于究竟什么是合法的,什么不是合法的争论太多了,以至于模式组决定,就有效性而言,任何事情都可以。