Función PHP xml_set_element_handler()
❮ Referencia del analizador PHP XML
Ejemplo
Especifique las funciones que se llamarán al principio y al final de un elemento en el documento XML ( note.xml ):
<?php
$parser=xml_parser_create();
function start($parser,$element_name,$element_attrs)
{
switch($element_name) {
case "NOTE":
echo "NOTE<br>";
break;
case "TO":
echo "To: ";
break;
case "FROM":
echo "From: ";
break;
case "HEADING":
echo "Heading: ";
break;
case "BODY":
echo "Message: ";
}
}
function stop($parser,$element_name) {
echo "<br>";
}
function char($parser,$data) {
echo $data;
}
// Specify functions to be called at the start and end of an
element in the XML document
xml_set_element_handler($parser,"start","stop");
xml_set_character_data_handler($parser,"char");
$fp=fopen("note.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);
fclose($fp);
?>
Definición y uso
La función xml_set_element_handler() especifica las funciones que se llamarán al principio y al final de un elemento en el documento XML.
Nota: Los parámetros de inicio y finalización también pueden ser una matriz que contenga una referencia de objeto y un nombre de método.
Sintaxis
xml_set_element_handler(parser, start, end)
Valores paramétricos
Parameter | Description |
---|---|
parser | Required. Specifies the XML parser to use |
start | Required. Specifies a function to be called at the start of an element. The function must have three parameters:
|
end | Required. Specifies a function to be called at the end of an element.
The function must have two parameters:
|
Detalles técnicos
Valor devuelto: | VERDADERO sobre el éxito. FALSO en falla |
---|---|
Versión PHP: | 4.0+ |
❮ Referencia del analizador PHP XML