Search code examples
xmlxsdxsd-validationxml-validation

Why can an XML element of type xsd:anyURI contain a non-URI string?


This is currently what I have for my video element that can only contain an URI.

<xs:element name="video">
    <xs:simpleType>
        <xs:restriction base="xs:anyURI"/>
    </xs:simpleType>
</xs:element>

.. But for some reason I am still able to put garbage content inside of video element and it does not throw an error.

Thoughts?


Solution

  • You can simplify your declaration to merely,

    <xs:element name="video" type="xs:anyURI"/>
    

    but you still won't get a strict interpretation of what constitutes a URI because only modest obligations are imposed on minimally conforming processors with respect to URI syntax rules:

    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.