In PHP, xml_set_notation_decl_handler() registers the function that runs when the XML parser reads a notation declaration in a DTD.
A notation declaration gives a name to a data format, for example <!NOTATION gif SYSTEM "image/gif">. Notations are rarely used in modern XML, and everyday XML apps mainly need the element handler and the character data handler.
Syntax
Call xml_set_notation_decl_handler() with the values you need. Start with this line.
Your handler is called as handler(XMLParser $parser, string $notation_name, string|false $base, string|false $system_id, string|false $public_id). A missing system id or public id arrives as false. The declaration lives in the DOCTYPE, so the XML must start with a DTD for this handler to be called.
The DTD in this string declares two notations, gif and jpeg.
The parser calls the handler once for each declaration, in document order.
The handler stores the system id in an array that uses the notation name as the key.
The loop prints each name with its system id.
Frequently Asked Questions
It registers the function that the XML parser calls for every <!NOTATION ...> declaration found in the DTD of a document.
A notation is a name for a data format, declared in the DTD, such as <!NOTATION gif SYSTEM "image/gif">. It is mostly used together with unparsed entities.
Notations only appear inside a DOCTYPE. If your XML has no DTD, or the DTD declares no notations, the handler stays silent.
A notation may use a public id only. When a value is missing, PHP passes false for it, so compare with === false before using it as a string.
Usually not. Everyday XML reading only needs xml_set_element_handler() and xml_set_character_data_handler(). This handler is for tools that inspect DTDs.