Two days ago we mentioned base URIs. I wonder when I will start using IRI in a consistent matter. Today I will provide some examples and tell you what the resulted location is. Note that this is only true for retrieval actions. Things like <form action="">
are treated differently. Assume I have a XHTML plus xml:base
profile, all elements in this post are in the http://www.w3.org/1999/xhtml
namespace, unless stated otherwise.
<a xml:base="http://example.org/test" href="http://example.org/test#foo"/>
<a xml:base="http://example.org/test" href="#foo"/>
Both links are same document references, regardless where the document in question is stored. The rules for this are quite simple. Resolve all URIs against the base URI. When, after removing the fragment identifier from both, and optionally normalizing both, the base URI is the same as the URI that was resolved against it are the same, the URI is a same-document reference. So http://example.org/test#foo
in the above example does not really point to that location, it points an element with an attribute of type ID with the value foo
in the current document, where ever that may be.
Now the base rules are explained, here are some more examples:
<a xml:base="http://example.org/" href="/test"/>
This points to http://example.org/test
.
<a xml:base="http://example.org/test" href="http://example.org/test"/>
<a xml:base="http://example.org/test" href="/test"/>
Both examples point to the document they are used in. They do not point to http://example.org/test
unless the document was really hosted at http://example.org/test
.
<a xml:base="http://Example.org/test" href="http://example.org/test"/>
Depends if URIs are normalized. If they are not normalized the link points to http://example.org/test
. If URIs are normalized it points to the document it was used in. Fun! In practice normalization almost never happens as it is insanely complicated.
<a xml:base="http://example.org/test#foo" href="http://example.org/test#foo"/>
This is a same-document reference. Fragment identifiers have to be removed from both the base URI and the URIs that are resolved against it.
Many thanks to Sjoerd for helping out. Next time we might address more than just retrieval. I should probably mention that web browsers do not follow this, defined in internet standard 66. Parts are incompatible with the web. I should also mention that this applies to the base
element as well. Obviously.
So the xml:base
attribute is more important to resolving URI's than the current, real location?
They do not point to
http://example.org/test
unless the document was really hosted athttp://example.org/test
.
(This is a same-document blockquote. There's no ID for the content.)
Point to
is really sloppy wording. The 2 examples do not retrieve the resource at http://example.org/test
, but they do resolve to http://example.org/test
. Where they are hosted is irrelevant.
Parts are incompatible with the web.
Are you sure? RFC 2396 was incompatible with the web, so most browsers still relied on RFC 1808. I thought RFC 3986 was meant to fix these problems (amongst other things).
So the
xml:base
attribute is more important to resolving URI's than the current, real location?
xml:base
attributes, and html:base
elements, are meant as real location
replacements.
*holding head* What? I thought I understood all this. Anne, any chance of an English translation? The base attribute and element should point to the source document yeah? The original document the elements are from? Or maybe the document you're currently viewing?
Gah!!
To be more specific: the href DOM property will return http://http://example.org/test
or http://http://example.org/test#foo
in all examples. If the base URI is http://http://example.org/test
then clicking on the links will let the browser scroll to the top of the page or to #foo
. If the base URI is something else, then the browser wil navigate to http://http://example.org/test
.
So the way I use it (and see it being used on the live web) is wrong then? Do I understand that right or am I just being thick?
I.e. I use it as the URI where the index page of the site can be found, and to which relative URIs should be resolved.
Yes. With a conforming browser, the links on your site to your homepage would be a same-document reference, and the only effect clicking it would have is to scroll to the top of the page.
So, to take the example of Ben’s site, the menu section (id="nav"
) should have a base URI that is something like:
http://dev.d10e.net/nb/menu.html
(whether or not the menu is really present at that URI doesn’t really matter) ??? It does correspond to the ‘the menu is (semi-)included content’ line of thinking...
Phooey, trying to understand this properly seems to be quite brain-wrecking ;p.
~Grauw