XInclude Java Eclipse JDK Sun XPath DOM SAX XALAN

setXIncludeAware

public void setXIncludeAware(boolean state)

XInclude 処理の状態を設定します。

ドキュメントインスタンスに XInclude マークアップが見つかった場合、「XML Inclusions (XInclude) Version 1.0」に指定されているとおりに処理する必要があります。

XInclude 処理のデフォルトは false に設定されます。

パラメータ:
state - XInclude 処理を true または false に設定する
例外:
UnsupportedOperationException - 下位互換性のため、JAXP の以前のバージョンを使用している場合に、この例外がスローされる
導入されたバージョン:
1.5

isXIncludeAware

public boolean isXIncludeAware()

XInclude 処理の状態を取得します。

戻り値:
XInclude 処理の現在の状態
例外:
UnsupportedOperationException - 下位互換性のため、JAXP の以前のバージョンを使用している場合に、この例外がスローされる
導入されたバージョン:

CDATAセクション内で、この行を適切に別扱いとするためには、少なくとも 「if prices[guesses[contestant]]]]>1000:」程度の複雑さを持つものが必要です。また、私はここまでの例でPythonコードを使っていますが、Pythonで別扱いが必要になる場合は、比較的稀だということにも注意してください。もし、XMLの例で記事を書いているとすれば、(余りにも多くて)とても手作業で別扱いにできるものではありません。そして、このような 「]]<」文字列の事例は、ずっと多くなるでしょう(例えば、XMLのリスト自体がCDATAセクションを持っている場合など・・・)。

もちろん、こうした困難に対処する方法はありますが、記事の中でコードの包含を扱うために最も容易な方法として私が見つけたのは、XIncludeの parse="text" 機能を使うものです。この属性を xi:include 要素に追加することによって、その結果は自動的にXMLのCDATAとして構文解析されるので、包含したとき自動的に別扱いされます。リスト5は、このようにXIncludeを使う文書の例です。
リスト5. テキスト型XIncludeを使ってサンプル・コードが挿入される文書






On-line game show programming in <a class="keyword" href="http://d.hatena.ne.jp/keyword/Python">Python</a>



A simple example

Examine the following code:


example 1

xi:include要素は、gameshow1.py(例えばリスト1)の完全に別扱いされた内容で置き換えられ、それはその要素のベースURIに対して決定されます。parse="text" のおかげで、この別扱いは自動的に行われます。私は常に encoding属性を使うようにしています(ちなみにこれは、parse="xml" を使うと無視されます)。私自身の使い方では、Pythonファイルに対してはエンコードに「iso-8859-1」を使い、XMLファイルには「utf-8」を使います。ただし皆さんの環境では、エンコーディングが異なるかも知れません。

XIncludeで構文解析されたテキストは、私が正にこうしたdeveloperWorks の記事を準備する時に使う手法です(この手法は素晴らしいことに、充分によく設計されたXMLフォーマットで記事のドラフトを渡すように著者に要求するのです)。これは私にとって、執筆の生産性を大きく向上させるものとなっています。

もう一つ、注意と警告を書いておきます。この本では、XIncludeの名前空間として 「http://www.w3.org/2003/XInclude」 を使っています。これは、この本の執筆時点では最新だったのですが、もはや最新ではありません。W3Cのワーキング・グループでは、2004年4月13日の勧告候補で、最初の名前空間http://www.w3.org/2001/XInclude」に戻してしまったのです。私が知っている大部分のツールは、後者(2001年)の名前空間しかサポートしていません。W3Cが後戻りを決めたのもそのせいかもしれませんが、この名前空間の変更によって、ちょっとした混乱が起きています。この本の著者達は気の毒な犠牲者だと言うことができ、私は出版社に対して訂正依頼を提出しています。

XInclude

XOM supports XInclude including the XPointer element() scheme and bare name XPointers. It does not support the XPointer xpointer() scheme. While internally the XInclude code is one of the ugliest parts of XOM, externally it is extremely simple. You merely pass a Document object to the static XIncluder.resolve() method, and you get back a new Document object in which all xi:include elements have been replaced by the content they refer to. The original Document object is not changed. For example,

Document input = builder.build(url);
Document result = XIncluder.resolve(input);

If something should go wrong during the inclusion process, either an IOException, an XIncludeException, or one of its subclasses is thrown as appropriate. For example, if a xi:include element were to attempt to include itself, either directly or indirectly, an InclusionLoopException would be thrown.

You have the option to specify a Builder to be used for including. This would allow you to validate the included documents or install a custom NodeFactory that returned instances of particular subclasses. For example, this code fragment throws a ValidityException if the master document or any of the documents it includes, directly or indirectly, are invalid:

try {
Builder builder = new Builder(true);
Document input = builder.build("http://www.example.org/master.xml");
Document result = XIncluder.resolve(input, builder);
}
catch (ValidityException ex) {
System.err.println("Validity error in " + ex.getURI());
}

XInclude 重要性● 人気度● 見通し●

 「XInclude」は、XMLドキュメントの全体、もしくはその一部を現行のドキ?<塔gの中にコピーするための手法だ。XIncludeを用いることで、開発者は、アプリケーションの開発中にドキュメント間のカット&ペーストという退屈な作業を行う必要がなくなる。ちなみに、XIncludeでは、後述する「XPointer」と「XPath」を用いて、どの書類にどの書類要素を含めるかを指定するようになっている。
 現在、XIncludeはW3Cによる規格化検討プロセスの初期段階にあるが、承認が有望視されている。恐らくこの技術が、現行のXML実装の空白を埋めることになるだろう。