Latest web development tutorials

PHP xml_set_processing_instruction_handler () function

PHP XML Reference Complete PHP XML Reference

Definition and Usage

xml_set_processing_instruction_handler () function to find the parser when processing instructions specified in the XML document is called a function.

Processing instructions contained in the <? And?> Delimiters, and contains a target with data.

Example: In this example, the processing instruction associates a style sheet and an XML document:

<?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>

If successful, the function returns TRUE. If it fails, it returns FALSE.

grammar

xml_set_processing_instruction_handler(parser,handler)

参数 描述
parser 必需。规定要使用的 XML 解析器。
handler 必需。规定当解析器找到处理指令时被调用的函数。

By the function "handler" parameter must have three parameters specified:

参数 描述
parser 必需。规定一个变量,包含调用处理器的 XML 解析器。
target 必需。规定一个变量,包含处理指令目标。
data 必需。规定一个变量,包含处理指令数据。


Tips and Notes

NOTE: handler can also be a parameter that contains an array of object references and method names.


Examples

<?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);
?>


PHP XML Reference Complete PHP XML Reference