xs:anyURI

The primitive type xs:anyURI represents a Uniform Resource Identifier (URI) reference. The value has to be a lexically valid URI reference. Since the bare minimum rules for valid URI references are fairly generic, most implementations accept most character strings, including a zero-length string. The only values that are not accepted are those that make inappropriate use of reserved characters, such as those that contain multiple # characters or have % characters that are not followed by two hexadecimal digits.

Some URI processors require that certain non-ASCII characters be escaped using a percent sign (%) followed by a two-digit Unicode code point. However, the xs:anyURI type does accept these characters escaped or unescaped. Table B-1 shows some examples of valid and invalid URI references.

For more information on URIs, see "Working with URIs" in Chapter 20.

Table B-1. Values of the xs:anyURI type

Values

Explanation

Valid

 
http://datypic.com

Absolute URI (in this case, an HTTP URL)

http://datypic.com/prod.html#shirt

Absolute URI with fragment identifier

mailto:[email protected]

Absolute URI using mailto scheme

../%C3%A9dition.html

Relative URI with escaped non-ASCII character

../édition.html

Relative URI with unescaped non-ASCII character

../prod.html#A557

Relative URI with fragment identifier

urn:datypic:com

Absolute URI (in this case, a URN)

 

Empty values are allowed

Invalid

 
http://datypic.com#frag1#frag2

Too many fragment identifiers (# characters)

http://datypic.com#f%rag

% character followed by something other than two hexadecimal digits

Casting and Comparing xs:anyURI Values

Values of type xs:anyURI can be cast to and from xs:string or xs:untypedAtomic. No escaping or unescaping occurs when values are cast among these types. To escape reserved characters in URIs, use one of the functions iri-to-uri, escape-html-uri, or encode-for-uri.

In addition, xs:anyURI values are automatically promoted to xs:string whenever a string is expected by a function or operator. For example, you could pass an xs:anyURI value to the substring function, or to the escape-uri function, both of which expect an xs:string value as their first argument. This also means that xs:anyURI values can be compared to strings and sorted with them.

Two xs:anyURI values are considered equal if they have identical characters (based on Unicode code points). This means that if they are capitalized differently, they are considered different values, even if they may be seemingly equivalent URLs. For example, http://datypic.com/prod is not equal to http://datypic.com/proD, because the last letter is capitalized differently.

Values of type xs:anyURI that are relative URIs are also compared based on code points, and no attempt is made to determine or compare their base URI. For example, ../prod is always equal to ../prod, even if the two xs:anyURI values may have come from different XHTML documents with different base URIs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.181