搜尋
首頁後端開發php教程Justin bieber Baby mv 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)。
function xslt_transform($xml,$xsl) {
  // Create a XSLTProcessorFactory object. XSLTProcessorfactory is an
$XSLTProcessorFactory = new java("org.apache.xalan.xslt.XSLTProcessorFactory");
  // Use the XSLTProcessorFactory method getProcessor() to create a
 ///SL. XSLTProcessorFactory->getProcessor();
  // Use XSLTInputSource objects to provide input to the XSLTProcessor
  // process() method for transformation. 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, filename。 // must be fully resolved.
  $xmlID = new java("org.apache.xalan.xslt.XSLTInputSource", $xml);
  $stylesheetID = new java("org.ache.xalanlan.apache.xalan.aplt. XSLTInputSource", $xsl);
  // Create a stringWriter object for the output.
  $stringWriter = new java("java.io.StringWriter");
Cre 5/java("java.io.StringWriter");
Cre with the XSLTResultTarget
  // class. Parameter of XSLTResultTarget is (in this case) a 'character
  // stream', which is the stringWriter object.  // stream', which is the stringWriter object.  // stream', which is the stringWriter object. xalan.xslt.XSLTResultTarget", $stringWriter);
  // Process input with the XSLTProcessors' method process(). This
  // method lacuses the XSL styleTleet to transform the the result in the result target.
  $XSLTProcessor->process($xmlID,$stylesheetID,$resultTarget);
  // Use the stringWriters' method toString() to
 , the bf/o/curf value as a string to get the
  // transformed result.
  $result = $stringWriter->toString();
  $stringWriter->close();
>}
?>
函數定義好後,我們就可以呼叫它了,在下面的例程中,變數$xml指向一個URL字串,$xsl也是如此。這個範例將顯示5個最新的phpbuilder.com文章標題。
$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;
?>
如果你在本地機上運行程序,必須確保你的函數參數指向正確的檔名。
$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

以上就介紹了justin bieber baby mv php&java(三),包含了justin bieber baby mv方面的內容,希望對PHP教程有興趣的朋友有所幫助。


陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
可以在PHP會話中存儲哪些數據?可以在PHP會話中存儲哪些數據?May 02, 2025 am 12:17 AM

phpsessionscanStorestrings,數字,數組和原始物。

您如何開始PHP會話?您如何開始PHP會話?May 02, 2025 am 12:16 AM

tostartaphpsession,usesesses_start()attheScript'Sbeginning.1)placeitbeforeanyOutputtosetThesessionCookie.2)useSessionsforuserDatalikeloginstatusorshoppingcarts.3)regenerateSessiveIdStopreventFentfixationAttacks.s.4)考慮使用AttActAcks.s.s.4)

什麼是會話再生,如何提高安全性?什麼是會話再生,如何提高安全性?May 02, 2025 am 12:15 AM

會話再生是指在用戶進行敏感操作時生成新會話ID並使舊ID失效,以防會話固定攻擊。實現步驟包括:1.檢測敏感操作,2.生成新會話ID,3.銷毀舊會話ID,4.更新用戶端會話信息。

使用PHP會話時有哪些性能考慮?使用PHP會話時有哪些性能考慮?May 02, 2025 am 12:11 AM

PHP会话对应用性能有显著影响。优化方法包括:1.使用数据库存储会话数据,提升响应速度;2.减少会话数据使用,只存储必要信息;3.采用非阻塞会话处理器,提高并发能力;4.调整会话过期时间,平衡用户体验和服务器负担;5.使用持久会话,减少数据读写次数。

PHP會話與Cookie有何不同?PHP會話與Cookie有何不同?May 02, 2025 am 12:03 AM

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHP如何識別用戶的會話?PHP如何識別用戶的會話?May 01, 2025 am 12:23 AM

phpIdentifiesauser'ssessionSessionSessionCookiesAndSessionId.1)whiwsession_start()被稱為,phpgeneratesainiquesesesessionIdStoredInacookInAcookInAcienamedInAcienamedphpsessIdontheuser'sbrowser'sbrowser.2)thisIdallowSphptpptpptpptpptpptpptpptoretoreteretrieetrieetrieetrieetrieetrieetreetrieetrieetrieetrieetremthafromtheserver。

確保PHP會議的一些最佳實踐是什麼?確保PHP會議的一些最佳實踐是什麼?May 01, 2025 am 12:22 AM

PHP會話的安全可以通過以下措施實現:1.使用session_regenerate_id()在用戶登錄或重要操作時重新生成會話ID。 2.通過HTTPS協議加密傳輸會話ID。 3.使用session_save_path()指定安全目錄存儲會話數據,並正確設置權限。

PHP會話文件默認存儲在哪裡?PHP會話文件默認存儲在哪裡?May 01, 2025 am 12:15 AM

phpsessionFilesArestoredIntheDirectorySpecifiedBysession.save_path,通常是/tmponunix-likesystemsorc:\ windows \ windows \ temponwindows.tocustomizethis:tocustomizEthis:1)useession_save_save_save_path_path()

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版