PHP 和 XML: 使用expat函數(一)

PHP 和 XML: 使用expat函數(一)

 

  可擴展標識語言(Extensible Markup Language )明顯是大多數開發人員將想要將其加入到他們的工具箱中的東西。XML是一種W3C的標準,它是開放的,語言中性的,API中性的,流式的,文本的,人類可讀 的, 並且是一種將結構化數據帶到web上的一種方法。XML是SGML的一個子集,它本身並不是一種標識 語言,但是 它允許作者來定義他們自已的標識語言,以便同分級數據保持更好的一致性。

 

  現在,用PHP 分析XML文檔已經不是一個象我以前在web和其它地方所看到的被覆蓋得很深的專題了。 在 PHP手冊中已經提供了一些對XML分析函數非常有用的信息,但是這個看上去好象就是我所能找到的 全部的信 息了。其它的語言看上去比PHP已經有了更多的關於XML的信息和工作實例,所以在這篇文章 中,我將試圖爲 改變這種情況作出我的一部分努力。

 

  我將帶領讀者體驗一個相當簡單的XML的應用,那個應用是爲我的網站所做的新聞系統的實現。我確實在 我的網站使用了這個應用,現在它工作的很好。如果你喜歡你可以自由地使用它。好了,讓我們開始吧!

 

  爲了在PHP中使XML分析函數有效,你需要一個支持XML 的模塊在你的web服務器上。這就意味着你將可能 不得不重新編譯你的模塊,以便可以支持XML,請參考這裏來查看如何做到的更多的信息。XML 分析函數現在 真正地包含在一種SAX分析器expat中,它提供了 關於XML的簡單的函數。另一種分析器是DOM分析器,它更容 易使用,關於它的一個例子就是微軟的MSXML分析器組件,它可以讓程序員通過操縱一種樹狀樣式的對象來處 理結點和元素。expat分析器(或任意的SAX 分析器)允許你分析一個XML文檔的實現方法是在對XML文檔進行分 析的時候對不同的標記類型指定回調函數來完成的。當分析器開始分析你的XML文檔並且遇上了一個標記,它 將調用你的函數,並且在繼續往下 執行之前由你的函數對特定的標記進行處理。你可以把它看作是一種事件 驅動的方法。

 

  讓我們看一個使用'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 HREF='http://www.romeo-must-die.com'

here </A

 

 

<IMG src="http://img.jcwcn.com/attachment/portal"


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章