六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

php&java(3)

[摘要]例子二:通過Xalan 1.2,使用XSLT轉換XML 做為第二個例子,我們使用了Xalan-java的XSLT引擎,這個引擎來自于APACHE的XML項目,使用這個程序,我們能夠使用XSL轉換XML源文件。這將極大的方便我們處理文檔和進行內容管理。 開始之前,我們需要將xerces.jar 和 ...
例子二:通過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&java(3) 
主站蜘蛛池模板: 诱人的无内裤女教师bd | 日本精高清区一 | 天天干夜夜想 | 天天躁日日躁狠狠躁黑人躁 | 日韩中文一区宇都宫紫苑 | 亚洲第一网站免费视频 | 亚洲 自拍 中文字幕 在线 | 午夜看片网站 | 中文字幕视频不卡 | 亚洲1页| 五月婷婷天 | 无码中文字幕乱在线观看 | 青草视频网站在线观看 | 色手机在线 | 小明看国产 | 亚洲偷偷 | 亚洲精品老司机 | 私库在线视频看看 | 午夜视频日本 | 最近新的免费韩国视频 | 天天晚上干白天干 | 日日摸夜夜添夜夜添成人 | 欧美性色欧美a在线播放 | 在线成人免费观看国产精品 | 在线观看视频h | 色婷丁香 | 色婷婷中文网 | 日韩欧美在线观看综合网另类 | 最新69堂国产成人精品视频 | 色视频亚洲| 日韩怡红院 | 青青草国产免费国产 | 香蕉狠狠再啪线视频 | 人人干在线 | 四虎在线精品免费高清在线 | 日韩欧美91 | 性荡视频 | 午夜影视网 | 日本www色视频成人免费免费 | 日本免费完整版观看 | 天天综合网久久 |