为什么类型 xsd:anyURI 的 XML 元素可以包含非 URI 字符串?
Why can an XML element of type xsd:anyURI contain a non-URI string?
目前我的 video
元素只能包含一个 URI。
<xs:element name="video">
<xs:simpleType>
<xs:restriction base="xs:anyURI"/>
</xs:simpleType>
</xs:element>
..但出于某种原因,我仍然能够将垃圾内容放入视频元素中,并且不会引发错误。
想法?
您可以将您的声明简化为,
<xs:element name="video" type="xs:anyURI"/>
但是您仍然无法对什么构成 URI 进行严格的解释,因为只有 适度的义务 被强加给最低限度符合要求的处理器关于 URI 语法规则:
3.2.17 anyURI
[...]
Note: Each URI scheme imposes specialized syntax rules for URIs in
that scheme, including restrictions on the syntax of allowed fragment
identifiers. Because it is impractical for processors to check that a
value is a context-appropriate URI reference, this specification
follows the lead of [RFC 2396] (as amended by [RFC 2732]) in this
matter: such rules and restrictions are not part of type validity and
are not checked by ·minimally conforming· processors. Thus in practice
the above definition imposes only very modest obligations on
·minimally conforming· processors.
目前我的 video
元素只能包含一个 URI。
<xs:element name="video">
<xs:simpleType>
<xs:restriction base="xs:anyURI"/>
</xs:simpleType>
</xs:element>
..但出于某种原因,我仍然能够将垃圾内容放入视频元素中,并且不会引发错误。
想法?
您可以将您的声明简化为,
<xs:element name="video" type="xs:anyURI"/>
但是您仍然无法对什么构成 URI 进行严格的解释,因为只有 适度的义务 被强加给最低限度符合要求的处理器关于 URI 语法规则:
3.2.17 anyURI
[...] Note: Each URI scheme imposes specialized syntax rules for URIs in that scheme, including restrictions on the syntax of allowed fragment identifiers. Because it is impractical for processors to check that a value is a context-appropriate URI reference, this specification follows the lead of [RFC 2396] (as amended by [RFC 2732]) in this matter: such rules and restrictions are not part of type validity and are not checked by ·minimally conforming· processors. Thus in practice the above definition imposes only very modest obligations on ·minimally conforming· processors.