做為第二個(gè)例子,我們使用了Xalan-java的XSLT引擎,這個(gè)引擎來(lái)自于APACHE的XML項(xiàng)目,使用這個(gè)程序,我們能夠使用XSL轉(zhuǎn)換XML源文件。這將極大的方便我們處理文檔和進(jìn)行內(nèi)容管理。

開(kāi) " /> 骚黄视频,免费看的黄网站,999久久久国产精品

中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

php&java(三)

例子二:通過(guò)Xalan 1.2,使用XSLT轉(zhuǎn)換XML

做為第二個(gè)例子,我們使用了Xalan-Java的XSLT引擎,這個(gè)引擎來(lái)自于APACHE的XML項(xiàng)目,使用這個(gè)程序,我們能夠使用XSL轉(zhuǎn)換XML源文件。這將極大的方便我們處理文檔和進(jìn)行內(nèi)容管理。

開(kāi)始之前,我們需要將xerces.jar 和 xalan.jar文件放入Java.class.path目錄下(這兩個(gè)文件包含在Xalan-Java 1.2 中,可以從xml.apache.org處下載)。
php程序如下:
函數(shù)xslt_transform()以XML和XSL文件為參數(shù),形式可為文件名(如: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);
}

?>

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

<?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;

?>

如果你在本地機(jī)上運(yùn)行程序,必須確保你的函數(shù)參數(shù)指向正確的文件名。

<?php

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

?>

雖然這種效果我們可以通過(guò)其它方法實(shí)現(xiàn),或許那些方法更好,但這個(gè)例子能讓你對(duì)php調(diào)用Java類(lèi)有一個(gè)更好的了解。

教程結(jié)束了,希望你能夠從這篇教程中學(xué)到點(diǎn)東西,以下是一些你用得到的鏈接:
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技術(shù)php&amp;amp;java(三),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: a毛片| 日韩欧美中文字幕在线视频 | 成人aaa视频 | 九九亚洲| 欧美三级成人理伦 | 国产精品国产精品国产专区不片 | 一区二区三区在线免费观看 | av超碰 | 国产精品一区在线观看 | 久草在线视频中文 | 中文字幕亚洲欧美日韩在线不卡 | 国产aⅴ| 成人在线精品视频 | 免费不卡视频 | 久久久成 | 综合九九| 日韩一区二区免费视频 | 欧美成人免费电影 | 色吧久久 | 玖玖免费 | 亚洲欧美综合精品另类天天更新 | 成人免费视频久久 | 波多野结衣一区二区 | 精品国产aⅴ | 欧美成人精品在线观看 | 亚洲毛片 | 亚州中文字幕 | 天堂成人国产精品一区 | 成人国产精品一级毛片视频毛片 | 97caoporn国产免费人人 | 一本色道久久综合亚洲精品高清 | 精品国产黄a∨片高清在线 成人区精品一区二区婷婷 日本一区二区视频 | 国产精品亚洲成在人线 | 人干人人| 少妇一级淫片免费放播放 | 很很干很很日 | 成人免费区一区二区三区 | 国产成人福利在线 | 天天干夜夜操 | 国产精品亚洲一区二区三区在线 | 日本一二三区电影 |