PHP 8.5.0 Alpha 1 available for testing

xml_set_default_handler

(PHP 4, PHP 5, PHP 7, PHP 8)

xml_set_default_handlerEstablece el gestor XML por defecto

Descripción

xml_set_default_handler(XMLParser $parser, callable|string|null $handler): true

Establece el gestor por defecto del analizador XML parser.

Parámetros

parser

El analizador XML.

handler

Si null se pasa, el controlador se reinicia a su estado por omisión.

Advertencia

Una cadena vacía también reiniciará el controlador, sin embargo esta funcionalidad está deprecada a partir de PHP 8.4.0.

Si handler es un callable, el callable se define como el controlador.

Si handler es una string, puede ser el nombre de un método de un objeto definido con xml_set_object().

Advertencia

Esta funcionalidad está deprecada a partir de PHP 8.4.0.

Advertencia

A partir de PHP 8.4.0, se verifica la validez del callable durante la configuración del controlador, y no en el momento de su llamada. Esto significa que xml_set_object() debe ser llamado antes de definir un método como cadena como devolución de llamada. Sin embargo, como este comportamiento también está deprecado a partir de PHP 8.4.0, se recomienda utilizar un callable adecuado para el método.

La firma del gestor debe ser:

handler(XMLParser $parser, string $data): void
parser
El analizador XML que llama al controlador.
data
data contiene los caracteres en forma de string. Puede ser una declaración XML, un tipo de documento, una entidad u otros datos para los cuales no se prevé ningún gestor.

Valores devueltos

Retorna siempre true.

Historial de cambios

Versión Descripción
8.4.0 Passing a non-callable string to handler is now deprecated, use a proper callable for methods, or null to reset the handler.
8.4.0 The validity of handler as a callable is now checked when setting the handler instead of checking when calling it.
8.0.0 parser ahora espera una instancia de XMLParser en lugar de un resource xml.
add a note

User Contributed Notes 3 notes

up
0
jp dot amarok at email dot cz
1 year ago
For anyone who was also wondering what kind of events this function actually handles:

it's used in cases when an XML comment is found or an additional declaration like an xml-stylesheet. In such cases the data argument contains the whole string as it is, for example:

<!-- this is a comment -->
<?xml-stylesheet title="mystyle" type="text/xsl" href="style.xsl" ?>
up
-2
phillip
20 years ago
it seems to me that in PHP5 the function defined as default-handler (using xml_set_default_handler()) doesen't get passed the cdata anymore:

i.e.:
xml_set_element_handler($this->parser, 'parseSTART', 'parseEND');
xml_set_default_handler($this->parser, 'parseDEFAULT');
function parseSTART() { ... }
function parseEND() { ... }
function parseDEFAULT() { ... }

under PHP5, parseDEFAULT will NOT get passed any cdata, but unter PHP4 it will. at least that's my take on the strange stuff (not) happening after migrating to PHP5.

my solution was to add a xml_set_character_data_handler($parser, 'parseDEFAULT'). it worked for me.
up
-3
anoril at anoril dot com
18 years ago
I have the same issue using two installation of PHP5: on accepts to use the default handler while the other only uses the character_data one.

Maybe a configuration problem...

;) Nonor.
To Top