ヘッダーをスキップ
Oracle XML Developer's Kitプログラマーズ・ガイド
10gリリース3(10.1.3)
B28611-01
  目次
目次
索引
索引

戻る
戻る
次へ
次へ
 

9 Pipeline Definition Language for Java

この章の内容は次のとおりです。

Pipeline Definition Languageの使用

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実装にはいくつかの違いがあります。次にその違いを示します。

Pipeline Definition Languageの詳細は、次の関連資料を参照してください。

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の順序で実行されます。

この例を実行するには、次の手順を実行します。

  1. xmlparserv2.jarおよび現在のディレクトリをCLASSPATHに追加します。

  2. makeを使用して、.classファイルを生成します。

  3. サンプル・プログラムを実行します。

    make demo
    
    

    または次のように実行します。

    java PipelineSample pipedoc.xml pipelog seq
    
    

    最初の引数(pipedoc.xml)は必須のパイプライン文書です。pipelogは名前を指定するオプションのログ・ファイルです。省略した場合、作成されるデフォルトのログ・ファイルはpipeline.logです。

    seqは引用符なしで入力したparaまたはseqのいずれかになります。seqは順次処理をリクエストします。省略した場合、デフォルト・モードはparaと入力した場合と同じ、パラレル・スレッドの処理モードになります。

  4. 作成されたパイプライン・ターゲット(この場合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

コマンドライン・パイプライン・ツールをorapipeといいます。最初にこのツールを実行する前に、CLASSPATHにxmlparserv2.jarを追加します。orapipeでは引数であるパイプライン文書(前述の項で示したコード例のpipedoc.xml)を少なくとも1つ含める必要があります。

orapipeを実行するには、次の構文を使用します。pipedocはあらかじめ作成する必須のパイプライン文書です。

orapipe options pipedoc

表9-1に、使用可能なオプションを示します。

表9-1 orapipe: コマンドライン・オプション

オプション 用途

-help

ヘルプ・メッセージを出力します。

-log logfile

名前を付けたログ・ファイルにエラーおよびメッセージを書き込みます。デフォルトはpipeline.logです。

-noinfo

情報項目をログに記録しません。デフォルトはオンです。

-nowarning

警告をログに記録しません。デフォルトはオンです。

-validate

パイプライン・スキーマで入力pipedocを検証します。デフォルトでは検証しません。

-version

バージョン番号を出力します。

-sequential

シーケンシャル・モードでパイプラインを実行します。デフォルトはパラレルです。