この章の内容は次のとおりです。
W3CのXML Pipeline Definition Languageを使用すると、XMLリソース間の処理関係を記述できます。パイプライン文書では、プロセスの入力と出力を指定します。パイプライン・コントローラはパイプライン文書を使用して、指定したプロセスを実行します。
Oracle XML Pipeline Processorは、2002年2月28日のW3CノートのXML Pipeline Definition Languageバージョン1.0に基づいて構築されています。このプロセッサは入力XMLパイプライン文書を受け入れ、派生した依存性に応じてパイプライン・プロセスを実行できます。パイプライン文書はXML文書であり、実行するプロセスを宣言方式で指定します。XML Pipeline Processorに加えて、XDKではパイプライン文書内で連結できる複数のパイプライン・プロセスを定義します。
W3CノートとOracle実装にはいくつかの違いがあります。次にその違いを示します。
パーサー・プロセス(DOMParserProcess
およびSAXParserProcess
)がXMLパイプラインに追加されています(ノートのセクション1)。
現在XML Baseはサポートされていません(セクション2.1)。
使用可能なパイプライン入力に関する最終ターゲット出力が最新のものになっているかどうかを確認するには、最終ターゲット出力のみを確認します。すべてのプロセスの中間出力が最新であるかどうかは確認されません(セクション2.2)。
select属性では、二重引用符("")の間にあるものはすべてリテラル文字列と考えられます。
1つのプロセスで同じInformation Setが作成された場合、プロセッサではエラーが発生します(セクション2.4.2.3)。
document要素は冗長機能であるためサポートされていません(セクション2.4.2.8)。
Pipeline Definition Languageの詳細は、次の関連資料を参照してください。
この例のファイルは、/xdk/demo/java/pipeline/
にあります。アプリケーションPipelineSample.java
は、pipedoc.xml
という名前のパイプライン文書(Pipeline Definition Languageのインスタンス)をコールします。この文書では、使用するスタイルシートをbook.xsl
、出力HTMLファイルをmyresult.html
、解析するXML文書をbook.xml
とします。プロセスはpipedoc.xml
に指定された順序ではp2、p3およびp1となります。ただし、p1、p2、p3の順序で実行されます。
この例を実行するには、次の手順を実行します。
xmlparserv2.jar
および現在のディレクトリをCLASSPATH
に追加します。
make
を使用して、.class
ファイルを生成します。
サンプル・プログラムを実行します。
make demo
または次のように実行します。
java PipelineSample pipedoc.xml pipelog seq
最初の引数(pipedoc.xml
)は必須のパイプライン文書です。pipelog
は名前を指定するオプションのログ・ファイルです。省略した場合、作成されるデフォルトのログ・ファイルはpipeline.log
です。
seq
は引用符なしで入力したparaまたはseqのいずれかになります。seqは順次処理をリクエストします。省略した場合、デフォルト・モードはparaと入力した場合と同じ、パラレル・スレッドの処理モードになります。
作成されたパイプライン・ターゲット(この場合myresult.html
)を表示します。
Javaプログラムでコールするエラー・ハンドラはPipelineSampleErrHdlr.java
です。
次に、処理を開始した入力XML文書book.xml
を示します。
<?xml version="1.0"?> <booklist> <book> <title>Twelve Red Herrings</title> <author>Jeffrey Archer</author> <publisher>Harper Collins</publisher> <price>7.99</price> </book> <book> <title language="English">The Eleventh Commandment</title> <author>Jeffrey Archer</author> <publisher>McGraw Hill</publisher> <price>3.99</price> </book> <book> <title language="English" country="USA">C++ Primer</title> <author>Lippmann</author> <publisher>Harper Collins</publisher> <price>4.99</price> </book> <book> <title>Emperor's New Mind</title> <author>Roger Penrose</author> <publisher>Oxford Publishing Company</publisher> <price>15.9</price> </book> <book> <title>Evening News</title> <author>Arthur Hailey</author> <publisher>MaMillan Publishers</publisher> <price>9.99</price> </book> </booklist>
次にパイプライン文書pipedoc.xml
を示します。
<pipeline xmlns="http://www.w3.org/2002/02/xml-pipeline" xml:base="http://example.org/"> <param name="target" select="myresult.html"/> <processdef name="domparser.p" definition="oracle.xml.pipeline.processes.DOMParserProcess"/> <processdef name="xslstylesheet.p" definition="oracle.xml.pipeline.processes.XSLStylesheetProcess"/> <processdef name="xslprocess.p" definition="oracle.xml.pipeline.processes.XSLProcess"/> <process id="p2" type="xslstylesheet.p" ignore-errors="false"> <input name="xsl" label="book.xsl"/> <outparam name="stylesheet" label="xslstyle"/> </process> <process id="p3" type="xslprocess.p" ignore-errors="false"> <param name="stylesheet" label="xslstyle"/> <input name="document" label="xmldoc"/> <output name="result" label="myresult.html"/> </process> <process id="p1" type="domparser.p" ignore-errors="true"> <input name="xmlsource" label="book.xml "/> <output name="dom" label="xmldoc"/> <param name="preserveWhitespace" select="true"></param> <error name="dom"> <html xmlns="http://www/w3/org/1999/xhtml"> <head> <title>DOMParser Failure!</title> </head> <body> <h1>Error parsing document</h1> </body> </html> </error> </process> </pipeline>
次にスタイルシートbook.xsl
を示します。
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:template match="/"> <HTML> <HEAD> </HEAD> <xsl:apply-templates/> </HTML> </xsl:template> <!-- document xsl:template --> <xsl:template match="booklist"> <BODY BGCOLOR="#CCFFFF"> <H1>List of books</H1> <P> This will illustrate the transformation of an XML file containing a list of books to an HTML table form </P> <xsl:apply-templates/> </BODY> </xsl:template> <xsl:template match="booklist/book"> <BR><B><xsl:apply-templates/></B></BR> </xsl:template> <xsl:template match="booklist/book/title"> <xsl:apply-templates/> </xsl:template> <xsl:template match="booklist/book/author"> <xsl:apply-templates/> </xsl:template> <xsl:template match="booklist/book/publisher"> </xsl:template> <xsl:template match="booklist/book/price"> Price: $<xsl:apply-templates/> </xsl:template> </xsl:stylesheet>
出力は/log
サブディレクトリのmyresult.html
です。
<?xml version = '1.0'?> <HTML><HEAD/><BODY BGCOLOR="#CCFFFF"><H1>List of books</H1><P> This will illustrate the transformation of an XML file containing list of books to an HTML table form </P> <BR/> Twelve Red Herrings Jeffrey Archer Price: $7.99 <BR/> The Eleventh Commandment Jeffrey Archer Price: $3.99 <BR/> C++ Primer Lippmann Price: $4.99 <BR/> Emperor's New Mind Roger Penrose Price: $15.9 <BR/> Evening News Arthur Hailey Price: $9.99 </BODY></HTML>
コマンドライン・パイプライン・ツールをorapipe
といいます。最初にこのツールを実行する前に、CLASSPATHにxmlparserv2.jar
を追加します。orapipe
では引数であるパイプライン文書(前述の項で示したコード例のpipedoc.xml
)を少なくとも1つ含める必要があります。
orapipeを実行するには、次の構文を使用します。pipedoc
はあらかじめ作成する必須のパイプライン文書です。
orapipe options pipedoc
表9-1に、使用可能なオプションを示します。
表9-1 orapipe: コマンドライン・オプション
オプション | 用途 |
---|---|
|
ヘルプ・メッセージを出力します。 |
|
名前を付けたログ・ファイルにエラーおよびメッセージを書き込みます。デフォルトは |
|
情報項目をログに記録しません。デフォルトはオンです。 |
|
警告をログに記録しません。デフォルトはオンです。 |
|
パイプライン・スキーマで入力 |
|
バージョン番号を出力します。 |
|
シーケンシャル・モードでパイプラインを実行します。デフォルトはパラレルです。 |