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


Posted in PHP onOctober 09, 2006

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 >

PHP 相关文章推荐
MySQL相关说明
Jan 15 PHP
php include,include_once,require,require_once
Sep 05 PHP
php数组总结篇(一)
Sep 30 PHP
PHP简洁函数小结
Aug 12 PHP
zf框架的registry(注册表)使用示例
Mar 13 PHP
ThinkPHP3.1新特性之对页面压缩输出的支持
Jun 19 PHP
php将图片保存入mysql数据库失败的解决方法
Dec 27 PHP
php调整服务器时间的方法
Apr 03 PHP
学习php设计模式 php实现原型模式(prototype)
Dec 07 PHP
PHP中TP5 上传文件的实例详解
Jul 31 PHP
PHP CURL实现模拟登陆并上传文件操作示例
Jan 02 PHP
基于php+MySql实现学生信息管理系统实例
Aug 04 PHP
用PHP动态生成虚拟现实VRML网页
Oct 09 #PHP
其他功能
Oct 09 #PHP
PHP新手上路(十一)
Oct 09 #PHP
PHP新手上路(十二)
Oct 09 #PHP
PHP新手上路(十三)
Oct 09 #PHP
PHP新手上路(十四)
Oct 09 #PHP
PHP简介
Oct 09 #PHP
You might like
2019年漫画销量排行榜:鬼灭登顶 海贼单卷制霸 尾田盛赞鬼灭
2020/03/08 日漫
mysql 字段类型说明
2007/04/27 PHP
php设计模式 Observer(观察者模式)
2011/06/26 PHP
php的ZipArchive类用法实例
2014/10/20 PHP
Yii2框架BootStrap样式的深入理解
2016/11/07 PHP
PHP实现的登录页面信息提示功能示例
2017/07/24 PHP
win10下 php安装seaslog扩展的详细步骤
2020/12/04 PHP
javascript 简单抽屉效果的实现代码
2010/03/09 Javascript
JS控制显示隐藏兼容问题(IE6、IE7、IE8)
2010/04/01 Javascript
js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色
2010/05/27 Javascript
javascript获取URL参数与参数值的示例代码
2013/12/20 Javascript
javascript使用switch case实现动态改变超级链接文字及地址
2014/12/16 Javascript
js+css实现的圆角边框TAB选项卡滑动门代码分享(2款)
2015/08/26 Javascript
学习javascript面向对象 实例讲解面向对象选项卡
2016/01/04 Javascript
Angular使用ng-messages与PHP进行表单数据验证
2016/12/28 Javascript
JS与jQuery判断文本框还剩多少字符可以输入的方法
2018/09/01 jQuery
vue-cli3 项目优化之通过 node 自动生成组件模板 generate View、Component
2019/04/30 Javascript
nodejs简单抓包工具使用详解
2019/08/23 NodeJs
JS通用方法触发点击事件代码实例
2020/02/17 Javascript
基于JS正则表达式实现模板数据动态渲染(实现思路详解)
2020/03/07 Javascript
[02:12]2019完美世界全国高校联赛(春季赛)报名开启
2019/03/01 DOTA
详解Python读取配置文件模块ConfigParser
2017/05/11 Python
Python设计模式之建造者模式实例详解
2019/01/17 Python
python实现UDP协议下的文件传输
2020/03/20 Python
java关于string最常出现的面试题整理
2021/01/18 Python
日本即尚网:JSHOPPERS.com(支持中文)
2019/12/03 全球购物
英国在线药房和在线药剂师:Chemist 4 U
2020/01/05 全球购物
英国豪华家具和家居用品购物网站:Teddy Beau
2020/10/12 全球购物
德国二手设计师时装和复古时装跳蚤市场:Mädchenflohmarkt
2020/11/09 全球购物
武汉高蓝德国际.net机试
2016/06/24 面试题
销售自我评价
2013/10/22 职场文书
最美护士演讲稿
2014/08/27 职场文书
大学生党员暑假实践(活动总结)
2019/08/21 职场文书
golang 实现菜单树的生成方式
2021/04/28 Golang
java实现对Hadoop的操作
2021/07/01 Java/Android
JavaScript中的LHS和RHS分析详情
2022/04/06 Javascript