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

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

PHP 中的 xml_set_default_handler() 函数


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

Definition and Usage
定义和用法

The xml_set_default_handler() function sets the default data handler for the XML parser.
xml_set_default_handler()函数的作用是:为XML解析器设置默认处理的数据处理函数。

This function specifies what function to be called whenever the parser finds data in the XML file.
这个函数指定了当解析器在XML文件中查找数据时需要请求什么函数。

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

Syntax
语法

xml_set_default_handler(parser,handler)

Parameter参数 Description描述
parser Required. Specifies XML parser to use
必要参数。指定需要使用的XML解析器
handler Required. Specifies a function to be used as an event handler
必要参数。指定一个作为事件处理器需要使用的函数

The Function specified by the "handler" parameter must have two parameters:
这个通过“handler”参数所指定的函数必须包含两个参数:

Parameter参数 Description描述
parser Required. Specifies a variable containing the XML parser calling the handler
必要参数。指定一个包含XML解析器的可用值
data Required. Specifies a variable containing the data from the XML file as a string
必要参数。指定包含XML文件的字符数据的一个变量(以字符串的形式)


Tips and Notes
注意点

Note: The data_handler parameter can also be an array containing an object reference and a method name.
注意:handler参数也可以是包含一个对象参数和一个方法名称的数组。


Example
案例

XML File
XML文件

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

PHP Code
PHP代码

<?php
$parser=xml_parser_create();
function default($parser,$data) { echo $data; }
xml_set_default_handler($parser,"default");
$fp=fopen("test.xml","r");
while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); }
xml_parser_free($parser);
?>

The output of the code above will be:
上述代码将输出下面的结果:

Tove Jani Reminder Don't forget me this weekend!

If you select "View source" in the browser window, you will see the following HTML:
如果你在浏览器中选择了“查看源文件”,你将看到下面的HTML代码:

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

评论 (0) All

登陆 | 还没注册?