7.2 xml:base


Before they can actually be used, relative URIs must be resolved into absolute URIs. A "base" URI is added as the initial portion of the absolute URI. Thus a URI such as

 website/images/picture.jpg 

if it appears in an HTML Web page fetched from

 https://foo.example.com/projects/ 

would be interpreted as

 https://foo.example.com/projects/website/images/picture.jpg 

This base information can be obtained from four sources [RFC 2396]:

  1. Base URI information embedded in the document containing the relative URI

  2. The URI of the object immediately containing the relative URI

  3. The URI used to retrieve the overall object in which the relative URI appears

  4. A base URI defined by the application context

Lower-numbered sources in this list dominate higher-numbered ones. XML security does not use Source 4 . Sources 2 and 3 are sometimes the same, but one URI might retrieve an enclosing object while the relative URI occurs within a nested object that has a different, possibly more specific URI.

To set embedded base URI information, you can use "xml:base". As Source 1 in the list, it dominates all other base URI sources. In particular, xml:base occurs as an attribute and sets the URI base at that node and all descendant nodes until it reaches one that overrides it. The XML in Example 7-1 produces the effective absolute URIs shown in Table 7-1. While this example uses "href", other attributes can have a URI in their value; likewise, URIs can be present in text content and processing instructions.

Example 7-1 Base, relative, and absolute URIs
 <foo xml:base="https://example.com/1/">   <bar href="data.jpg" />   <bar href="image.gif"  xml:base="ftp://10.0.0.1/">     <charlie href="delta/description.txt" />     <charlie href="http://xyz.example/cgi/" />   </bar>   <bar href="http://2/3/" /> </foo> 

You determine base URIs as follows:

  • The base URI for relative URIs appearing in an xml:base attribute value is the base URI for the parent of the element where the xml:base attribute appears, if one exists in the document or external entity. Otherwise, it is the URI of the document or external entity.

  • The base URI for relative URIs appearing in attributes other than xml:base is the base URI of the element in which the attribute appears.

  • The base URI for relative URIs appearing in text is the base URI of the element containing that text.

Table 7-1. Effecive URIs from Example 7-1
Element ID Where "href" Is Found Effective URI Notes
A https://example.com/1/data.jpg  
B ftp://10.0.0.1/image.gif  
C ftp://10.0.0.1/delta/description.txt  
D http://xyz.example/cgi/ The absolute URI is not affected by the base.
E https://example.com/2/3/ ".." in the relative path backs up over "1/" in the base URI path.

  • The base URI for relative URIs appearing in processing instructions is the base URI for the parent of the processing instruction, if one exists in the document or external entity. Otherwise, it is the URI of the document or external entity.



Secure XML(c) The New Syntax for Signatures and Encryption
Secure XML: The New Syntax for Signatures and Encryption
ISBN: 0201756056
EAN: 2147483647
Year: 2005
Pages: 186

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net