做為第二個例子,我們使用了Xalan-java的XSLT引擎,這個引擎來自于APACHE的XML項目,使用這個程序,我們能夠使用XSL轉換XML源文件。這將極大的方便我們處理文檔和進行內容管理。

開 " /> 国产欧美第一页,久久久久琪琪精品色,欧美巨大xxxx做受高清

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php&java(三)

例子二:通過Xalan 1.2,使用XSLT轉換XML

做為第二個例子,我們使用了Xalan-Java的XSLT引擎,這個引擎來自于APACHE的XML項目,使用這個程序,我們能夠使用XSL轉換XML源文件。這將極大的方便我們處理文檔和進行內容管理。

開始之前,我們需要將xerces.jar 和 xalan.jar文件放入Java.class.path目錄下(這兩個文件包含在Xalan-Java 1.2 中,可以從xml.apache.org處下載)。
php程序如下:
函數xslt_transform()以XML和XSL文件為參數,形式可為文件名(如:foo.xml)或URL(如:http://localhost/foo.xml)。

<?php

function xslt_transform($xml,$xsl) {

  // Create a XSLTProcessorFactory object. XSLTProcessorfactory is a Java
  // class which manufactures the processor for performing transformations.
  $XSLTProcessorFactory = new Java("org.apache.xalan.xslt.XSLTProcessorFactory");

  // Use the XSLTProcessorFactory method getProcessor() to create a
  // new XSLTProcessor object.
  $XSLTProcessor = $XSLTProcessorFactory->getProcessor();

  // Use XSLTInputSource objects to provide input to the XSLTProcessor
  // process() method for transformation. Create objects for both the
  // xml source as well as the XSL input source. Parameter of
  // XSLTInputSource is (in this case) a 'system identifier' (URI) which
  // can be an URL or filename. If the system identifier is an URL, it
  // must be fully resolved.
  $xmlID = new Java("org.apache.xalan.xslt.XSLTInputSource", $xml);
  $stylesheetID = new Java("org.apache.xalan.xslt.XSLTInputSource", $xsl);

  // Create a stringWriter object for the output.
  $stringWriter = new Java("Java.io.StringWriter");

  // Create a ResultTarget object for the output with the XSLTResultTarget
  // class. Parameter of XSLTResultTarget is (in this case) a 'character
  // stream', which is the stringWriter object.  
  $resultTarget = new Java("org.apache.xalan.xslt.XSLTResultTarget", $stringWriter);

  // Process input with the XSLTProcessors' method process(). This
  // method uses the XSL stylesheet to transform the XML input, placing
  // the result in the result target.
  $XSLTProcessor->process($xmlID,$stylesheetID,$resultTarget);

  // Use the stringWriters' method toString() to
  // return the buffer's current value as a string to get the
  // transformed result.
  $result = $stringWriter->toString();
  $stringWriter->close();
  return($result);
}

?>

函數定義好后,我們就可以調用它了,在下面的例程中,變量$xml指向一個URL字符串,$xsl也是如此。這個例子將顯示5個最新的phpbuilder.com文章標題。

<?php

$xml = "http://www.phpbuilder.com/rss_feed.php?type=articles&limit=5";
$xsl = "http://www.soeterbroek.com/code/xml/rss_html.xsl";
$out = xslt_transform($xml,$xsl);
echo $out;

?>

如果你在本地機上運行程序,必須確保你的函數參數指向正確的文件名。

<?php

$xml  = "/web/htdocs/xml_Java/rss_feed.xml";
$xsl  = "/web/htdocs/xml_Java/rss_html.xsl";
$out = xslt_transform($xml,$xsl);
echo $out;

?>

雖然這種效果我們可以通過其它方法實現,或許那些方法更好,但這個例子能讓你對php調用Java類有一個更好的了解。

教程結束了,希望你能夠從這篇教程中學到點東西,以下是一些你用得到的鏈接:
http://www.php4win.de ~ A great Win32 distribution of php
http://www.Javasoft.com ~ Sun's Java release
http://www.jars.com ~ Start searching for handy Java classes
http://www.gamelan.com ~ More Java classes
http://www.techNETcast.com/tnc_play_stream.html?stream_id=400 ~ Sam Ruby about php and Java integration at Open Source Convention 2000 (audio)
http://xml.apache.org ~ Apache XML Project
http://www.phpbuilder.com/columns/justin20001025.php3 ~ Transforming XML with XSL using Sablotron

php技術php&amp;amp;java(三),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 91久久综合精品国产丝袜长腿 | 被同桌摸出水来了好爽的视频 | 国产午夜精品美女免费大片 | 国产不卡一卡2卡三卡4卡网站 | 快插我我好湿啊公交车上做 | 色呦呦人人视频 | 日本人添下面的全过程 | 国产毛片女人18水多 | 国产精品久久久久久熟妇吹潮软件 | 蜜芽tv在线观看免费网站 | 色情www日本欧美 | 一天不停的插BB十几次 | 免费一级特黄欧美大片久久网 | 日本阿v直播在线 | 秋霞伦理手机在线看片 | 神马影院在线eecss伦理片 | 狠狠躁天天躁小说 | 亚洲综合色在线视频久 | 末班车动漫无删减免费 | 中文字幕精品AV内射夜夜夜 | 国产一在线精品一区在线观看 | 亚洲欧美中文字幕5发布 | 日韩经典欧美一区二区三区 | 国产精品自产拍在线观看网站 | 国产午夜在线观看视频播放 | 野花影院手机在线观看 | 国产成a人片在线观看视频99 | 99精品在线看 | 中国老妇xxxhd | 高清国产激情视频在线观看 | 欧美一级成人影院免费的 | 浓毛BWBWBWBWBW日本 | 国精产品一区一区三区M | 久久免费电影 | 国产东北男同志videos网站 | 久久精品在现线观看免费15 | 久久AAAA片一区二区 | 国产福利不卡在线视频 | 亚洲 日本 中文字幕 制服 | 正在播放国产尾随丝袜美女 | 亚洲无人区码二码三码区别图 |