当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > xml_set_processing_instruction

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 xml_set_processing_instruction


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

Definition and Usage
定义和用法

The xml_set_processing_instruction_handler() function specifies a function to be called when the parser finds a processing instruction in the XML document.
xml_set_processing_instruction_handler()函数的作用是:设置一个函数对XML文档中的指令进行处理。

A processing instruction is enclosed in <? and ?> delimiters and contains a a target followed by data.
这个指令是写在<? 和 ?>内的,它在数据之后还包含了目标。

Example: In this case the processing instruction associates a style sheet with an XML document:
案例:在这个情况下,指令可以和XML文档中的样式膘一起使用:

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

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

Syntax
语法

xml_set_processing_instruction_handler(parser,handler)

Parameter
参数
Description
描述
parser Required. Specifies XML parser to use
必要参数。指定需要使用的XML解析器
handler Required. Specifies a function to be when the parser finds a notation declaration
必要参数。指定处理ZML文档中符号声明的函数

The Function specified by the "handler" parameter must have three parameters:
这个函数所指定的“handler”参数必须包含下面五个参数:

Parameter
参数
Description
描述
parser Required. Specifies a variable containing the XML parser calling the handler
必要参数。指定一个包含XML解析器的可用值
target Required. Specifies a variable containing processing instruction target
必要参数。指定包含处理指令目标的变量
data Required. Specifies a variable containing processing instruction data
必要参数。指定包含处理指令数据的变量


Tips and Notes
注意点

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


Example
案例

<?php
$parser=xml_parser_create();
function char($parser,$data) { echo $data; }
function pi_handler($parser, $target, $data) { echo "Target: $target<br />"; echo "Data: $data<br />"; }
xml_set_character_data_handler($parser,"char");
xml_set_processing_instruction_handler($parser, "pi_handler");
$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);
?>

评论 (0) All

登陆 | 还没注册?