亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

php&java(三)

瀏覽:5日期:2024-02-27 08:52:12
例子二:通過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
標簽: Java
上一條:php&java(一)下一條:php&java(二)
主站蜘蛛池模板: 成人18xxxx网站 | 国产精品视频久久 | 毛片播放器 | 色噜噜狠狠在爱丁香 | 黄色亚洲片 | 任你躁欧美一级在线精品免费 | 日韩妞干网 | 久久一精品| 一区二区三区免费精品视频 | 欧美日韩国产58香蕉在线视频 | 精品久久免费视频 | 欧美成人亚洲高清在线观看 | 欧美一级久久久久久久久大 | 久久精品一区二区三区日韩 | 免费黄视频在线观看 | 1024免费观看 | 黄网在线免费观看 | 国产一区二区三区露脸 | 亚洲激情中文字幕 | 国产视频一二三 | 国产社区在线 | 亚洲精品国产摄像头 | 性色生活免费看性大片 | 野草在线观看视频精品 | 欧美特黄特刺激a一级淫片 欧美特黄高清免费观看的 欧美爱片 | 性生生活网站免费 | 亚洲日韩视频免费观看 | 免费三片在线观看网站 | 国产高清三级 | 91热成人精品国产免费 | 成人777777 | 三级黄色片在线观看 | 视频1区| 国产三级一区 | 成人高清在线视频 | 69男女囗交动态图视频 | bbixx在线观看 | 国产九九热视频 | 久久精品国产99久久香蕉 | 色综合天天色综合 | 欧美亚洲国产精品久久蜜芽 |