直播中
現(xiàn)在,用PHP 分析XML文檔已經(jīng)不是一個(gè)象我以前在web和其它地方所看到的被覆蓋得很深的專題了。 在
PHP手冊中已經(jīng)提供了一些對(duì)XML分析函數(shù)非常有用的信息,但是這個(gè)看上去好象就是我所能找到的 全部的信
息了。其它的語言看上去比PHP已經(jīng)有了更多的關(guān)于XML的信息和工作實(shí)例,所以在這篇文章 中,我將試圖為
改變這種情況作出我的一部分努力。
我將帶領(lǐng)讀者體驗(yàn)一個(gè)相當(dāng)簡單的XML的應(yīng)用,那個(gè)應(yīng)用是為我的網(wǎng)站所做的新聞系統(tǒng)的實(shí)現(xiàn)。我確實(shí)在
我的網(wǎng)站使用了這個(gè)應(yīng)用,現(xiàn)在它工作的很好。如果你喜歡你可以自由地使用它。好了,讓我們開始吧!
為了在PHP中使XML分析函數(shù)有效,你需要一個(gè)支持XML 的模塊在你的web服務(wù)器上。這就意味著你將可能
不得不重新編譯你的模塊,以便可以支持XML,請(qǐng)參考這里來查看如何做到的更多的信息。XML 分析函數(shù)現(xiàn)在
真正地包含在一種SAX分析器expat中,它提供了 關(guān)于XML的簡單的函數(shù)。另一種分析器是DOM分析器,它更容
易使用,關(guān)于它的一個(gè)例子就是微軟的MSXML分析器組件,它可以讓程序員通過操縱一種樹狀樣式的對(duì)象來處
理結(jié)點(diǎn)和元素。expat分析器(或任意的SAX 分析器)允許你分析一個(gè)XML文檔的實(shí)現(xiàn)方法是在對(duì)XML文檔進(jìn)行分
析的時(shí)候?qū)Σ煌臉?biāo)記類型指定回調(diào)函數(shù)來完成的。當(dāng)分析器開始分析你的XML文檔并且遇上了一個(gè)標(biāo)記,它
將調(diào)用你的函數(shù),并且在繼續(xù)往下 執(zhí)行之前由你的函數(shù)對(duì)特定的標(biāo)記進(jìn)行處理。你可以把它看作是一種事件
驅(qū)動(dòng)的方法。
讓我們看一個(gè)使用'Newsboy'類來分析的XML文檔
--------------------------------------------------------------------------------
mynews.xml
03/31/2000
Sooo Busy !
I haven't posted anything here for a while now as I have been busy with work(have to pay those
bills!).
I have just finished a neat little script that stores a complete record set in a session
variable after
doing an SQL query. The neat part is that an XML doc is stored in the session variable
an when paging
through the results (often near 1000!) the script displays 50 results at a time from the
XML doc in the
session variable instead of doing another query against the database. It takes a BIG load
off of the
database server.
03/25/2000
NewsBoy Class
Converted Newsboy to a PHP class to allow better abstraction (as far as PHP allows.)
Guess that means this is version 0.02 ?!
Newsboy will have a section of it's own soon on how to use and customize the class.
03/24/2000
NewsBoy is up!
I have just finished NewsBoy v0.01 !!!
It looks quite promising. You may ask, ""What the heck is it?!".
Well it's a simple news system for web-sites, written in PHP, that makes use of XML
for
the news data format allowing easy updating and portability between platforms.
It uses the built in expat parser for Apache.
This is just the very first version and there will be loads of improvements as the
project progresses.
03/24/2000
Romeo must Die
Saw a really cool movie today at Mann called 'Romeo must Die'
Nice fight scenes for a typical kung-fu movie with some 'Matrix' style effects.
One particular cool effect was the 'X-Ray Vision' effect that occured in various
fight scenes.
The hero, played by Jet Li, strikes a bad guy and you can see the bone in his arm
crack, in X-RAY vision.
There were some funny scenes too when Jet has to play American football with the
bad guys.
The official website for the movie is <A
> here </A>
<IMG SRC="http://a1996.g.akamaitech.net/7/1996/25/e586077a88e7a4/
romeomustdie.net/images/image15.jpg" WIDTH=300 >