Función PHP xml_set_processing_instruction_handler()
❮ Referencia del analizador PHP XML
Ejemplo
Cree un analizador XML, configure el controlador de datos de caracteres, configure el controlador PI y analice un documento XML ( note_pi.xml ):
<?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");
// Set up PI
handler
xml_set_processing_instruction_handler($parser, "pi_handler");
$fp=fopen("note_pi.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);
?>
Definición y uso
La función xml_set_processing_instruction_handler() especifica una función que se llamará cuando el analizador encuentre una instrucción de procesamiento (PI) en el documento XML.
Un PI está encerrado en <? y ?> y contiene un objetivo seguido de datos.
Ejemplo: En este caso el PI asocia una hoja de estilos con un documento XML:
<?xml version="1.0" encoding="UTF-8"?>
<?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>
Nota: el parámetro del controlador también puede ser una matriz que contenga una referencia de objeto y un nombre de método.
Sintaxis
xml_set_processing_instruction_handler(parser, handler)
Valores paramétricos
Parameter | Description |
---|---|
parser | Required. Specifies the XML parser to use |
handler | Required. Specifies a function to be used as an event handler. The function must
accept three parameters:
|
Detalles técnicos
Valor devuelto: | VERDADERO sobre el éxito. FALSO en falla |
---|---|
Versión PHP: | 4.0+ |
❮ Referencia del analizador PHP XML