av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

php&java(三)

瀏覽:8日期:2024-02-27 08:52:12
例子二:通過(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類有一個(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
標(biāo)簽: Java
上一條:php&java(一)下一條:php&java(二)
主站蜘蛛池模板: 亚洲精品久久久 | 九九热在线观看 | 中文字幕视频在线观看 | 特黄视频 | 亚洲精品一区中文字幕乱码 | 免费一级黄色电影 | 亚洲免费视频在线观看 | 午夜专区 | 盗摄精品av一区二区三区 | 国产美女精品视频 | 在线观看午夜视频 | 亚洲日本免费 | 91精品国产91久久久久久吃药 | 亚洲一区二区免费电影 | 国产一区二区三区久久久久久久久 | 久久88 | 国产一区二区在线看 | 国产精品国产精品国产专区不卡 | 欧美综合国产精品久久丁香 | 狠狠狠| 日韩中文字幕一区 | 国产黄色在线 | 免费黄色日本 | 91精品综合久久久久久五月天 | 在线免费黄色小视频 | 日韩久久久久久久 | h视频免费在线观看 | 四虎影音 | 亚洲444kkkk在线观看最新 | 国产欧美精品一区二区三区 | 影音先锋欧美资源 | 国产精品亚洲一区 | 国产精品69毛片高清亚洲 | 国产精品成人在线播放 | 欧美成人精品 | 国产综合视频 | 亚洲国产自产 | 欧美一级二级三级视频 | 99国产精品一区二区三区 | 精品视频在线免费观看 | com.国产 |