メインコンテンツまでスキップ

5. 参照解決 (Reference Resolution)

このセクションでは、URI参照を絶対形式に解決するアルゴリズムについて説明します。

5.1. ベースURIの確立 (Establishing a Base URI)

相対参照の解決にはベースURIが必要です。ベースURIはさまざまな方法で確立できます。

5.1.1. コンテンツに埋め込まれたベースURI (Base URI Embedded in Content)

HTMLの<base>タグなどのメカニズムを使用して、コンテンツ内でベースURIを指定できます。

5.1.2. カプセル化エンティティからのベースURI (Base URI from the Encapsulating Entity)

カプセル化エンティティ(MIMEメッセージなど)がベースURIを定義できます。

5.1.3. 取得URIからのベースURI (Base URI from the Retrieval URI)

他のベースURIが利用できない場合は、ドキュメントが取得されたURIを使用します。

5.1.4. デフォルトのベースURI (Default Base URI)

アプリケーションはデフォルトのベースURIを定義できます。

5.2. 相対解決 (Relative Resolution)

相対参照解決アルゴリズムの疑似コード:

if R.scheme is defined then
T.scheme = R.scheme
T.authority = R.authority
T.path = remove_dot_segments(R.path)
T.query = R.query
else
if R.authority is defined then
T.authority = R.authority
T.path = remove_dot_segments(R.path)
T.query = R.query
else
if R.path is empty then
T.path = Base.path
if R.query is defined then
T.query = R.query
else
T.query = Base.query
else
if R.path starts-with "/" then
T.path = remove_dot_segments(R.path)
else
T.path = merge(Base, R.path)
T.path = remove_dot_segments(T.path)
T.query = R.query
T.authority = Base.authority
T.scheme = Base.scheme
T.fragment = R.fragment

5.3. コンポーネントの再構成 (Component Recomposition)

解決されたコンポーネントをURI文字列に再結合します。

5.4. 参照解決の例 (Reference Resolution Examples)

ベースURI: http://a/b/c/d;p?q

相対参照解決結果
ghttp://a/b/c/g
./ghttp://a/b/c/g
g/http://a/b/c/g/
/ghttp://a/g
//ghttp://g
?yhttp://a/b/c/d;p?y
g?yhttp://a/b/c/g?y
#shttp://a/b/c/d;p?q#s
../ghttp://a/b/g
../../ghttp://a/g

次の章: 6. 正規化と比較 (Normalization and Comparison) - URI正規化技術