PHP xml_set_unparsed_entity_decl_handler() Function
Beginner
5 min read
Updated: Nov 2026
3 examples
XML Parser
Definition
In PHP, xml_set_unparsed_entity_decl_handler() registers the function that runs when the XML parser reads an unparsed entity declaration in a DTD.
An unparsed entity is a name for binary data such as an image, declared with the NDATA keyword, for example <!ENTITY logo SYSTEM "logo.gif" NDATA gif>. It is a rarely used DTD feature, and everyday XML apps mainly need the element handler and the character data handler.
Syntax
Call xml_set_unparsed_entity_decl_handler() with the values you need. Start with this line.
Your handler is called as handler(XMLParser $parser, string $entity_name, string|false $base, string $system_id, string|false $public_id, string $notation_name). It is called while the DTD is being read, so the XML must start with a DOCTYPE that declares an entity with NDATA.
Both handlers are registered on the same parser before xml_parse() runs.
The notation is declared first, so the notation handler prints its line first.
The entity declaration comes next, so the unparsed entity handler prints its line second.
Together the two lines show that logo is a gif file and that gif means image/gif.
Frequently Asked Questions
It registers the function the XML parser calls for each unparsed entity declared in a DTD, such as <!ENTITY logo SYSTEM "logo.gif" NDATA gif>.
It is a name for non-XML data, usually a binary file such as an image. It is declared with NDATA followed by the name of a notation.
It only runs for entities declared with NDATA inside a DOCTYPE. XML without a DTD, or with only normal entities, never triggers it.
The word after NDATA is the name of a notation. The notation, declared with <!NOTATION>, says what format the data has.
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.