当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > xml_set_对象() 函数

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 xml_set_对象() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 482 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The xml_set_object() function allows a parser to be used within an object.
xml_set_object()函数的作用是:在一个对象中使用XML解析器。

This function returns TRUE on success, or FALSE on failure.
如果函数执行成功,将返回True;如果执行失败将返回False。

Syntax
语法

xml_set_object(parser,object)

Parameter
参数
Description
描述
parser Required. Specifies XML parser to use
必要参数。指定需要使用的XML解析器
object Required. Specifies the object to set the parser to
必要参数。指定需要为解析器设置的对象
 

Example
案例

<?php
class XMLParser
{
var $xmlparser;
function XMLParser() { $this->xmlparser = xml_parser_create(); xml_set_object($this->xmlparser, $this); xml_set_character_data_handler($this->xmlparser,"char"); xml_set_element_handler($this->xmlparser, "start_tag","end_tag"); }
function parse($data) { xml_parse($this->xmlparser, $data); }
function parse_File($xmlfile) { $fp = fopen($xmlfile, 'r'); while ($xmldata = fread($fp, 4096)) {
 if (!xml_parse($this->xmlparser, $xmldata)) { //If error die( print "ERROR: " . xml_error_string(xml_get_error_code($this->xmlparser)) . "<br />Line: " . xml_get_current_line_number($this->xmlparser) . "<br />Column: " . xml_get_current_column_number($this->xmlparser) . "<br />"); } } }
function start_tag($xmlparser, $tag, $attributes) { print $tag . "<br />"; }
function end_tag(){}
function char($xmlparser,$data) { echo $data . "<br />"; }
function close_Parser() { xml_parser_free($this->xmlparser); }
}
$myxmlparser = new XMLParser();
$myxmlparser->parse_File("test.xml");
$myxmlparser->close_parser();
?>

评论 (0) All

登陆 | 还没注册?