phpday 2027 - Call for Papers

xml_set_default_handler

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

xml_set_default_handler — Imposta il gestore predefinito

Descrizione

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

Imposta la funzione di gestione predefinita per il parser XML parser.

Elenco dei parametri

parser

Il parser XML.

handler

Se viene passato null, il gestore viene reimpostato al suo stato predefinito.

Avviso

Anche una stringa vuota reimposta il gestore, tuttavia questo è deprecato a partire da PHP 8.4.0.

Se handler è un callable, il callable viene impostato come gestore.

Se handler è una string, può essere il nome di un metodo di un oggetto impostato con xml_set_object().

Avviso

Questo è deprecato a partire da PHP 8.4.0.

Avviso

A partire da PHP 8.4.0, la validità del callable viene verificata quando si imposta il gestore, non quando viene chiamato. Ciò significa che xml_set_object() deve essere chiamata prima di impostare una stringa di metodo come callback. Tuttavia, poiché anche questo comportamento è deprecato a partire da PHP 8.4.0, si raccomanda invece di usare un callable appropriato per il metodo.

La firma del gestore deve essere:

function handler(XMLParser $parser, string $data): void
parser

Il parser XML che chiama il gestore.

data

data contiene i dati carattere. Questi possono essere la dichiarazione XML, la dichiarazione del tipo del documento, entità o altri dati per i quali non esistono altri gestori.

Valori restituiti

Restituisce sempre true.

Log delle modifiche

Versione Descrizione
8.4.0 Passare un valore non callable di tipo string a handler è ora deprecato, usare un callable appropriato per i metodi, oppure null per reimpostare il gestore.
8.4.0 La validità di handler come callable viene ora verificata quando si imposta il gestore invece che quando lo si chiama.
8.0.0 parser ora si aspetta un'istanza di XMLParser; in precedenza, era prevista una risorsa xml valida di tipo resource.
+add a note

User Contributed Notes 3 notes

up
0
jp dot amarok at email dot cz
2 years 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
21 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
20 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