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

來源:互聯網
上載者:User
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://a1996.g.akamaitech.net/7/1996/25/e586077a88e7a4/
romeomustdie.net/images/image15.jpg" WIDTH=300 >

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.