Current Location: Home> Function Categories> xml_set_unparsed_entity_decl_handler

xml_set_unparsed_entity_decl_handler

Set up unresolved entity declaration handlers
Name:xml_set_unparsed_entity_decl_handler
Category:XML parser
Programming Language:php
One-line Description:Sets a processing function for unresolved entity declarations.

Definition and usage

xml_set_unparsed_entity_decl_handler() function is used to specify the function to be called when the parser encounters an unresolved entity in an XML document.

Note: The handler parameter can also be an array containing object references and method names.

Example

Create an XML parser, set up a character data handler, set up an unparsed entity declaration handler, and parse XML documents:

 <?php
$parser = xml_parser_create ( ) ;

function char ( $parser , $data ) {
  echo $data ;
}

function unparsed_ent_handler ( $parser , $entname , $base , $sysID , $pubID , $notname ) {
  print " $entname <br>" ;
  print " $sysID <br>" ;
  print " $pubID <br>" ;
  print " $notname <br>" ;
}

xml_set_character_data_handler ( $parser , "char" ) ;
// Set unresolved entity declaration handler
xml_set_unparsed_entity_decl_handler ( $parser , "unparsed_ent_handler" ) ;

$fp = fopen ( "test.xml" , "r" ) ;

while ( $data = fread ( $fp , 4096 ) ) {
  xml_parse ( $parser , $data , feof ( $fp ) ) or
  die ( sprintf ( "XML error: %s on line %d" ,
  xml_error_string ( xml_get_error_code ( $parser ) ) ,
  xml_get_current_line_number ( $parser ) ) ) ;
}
xml_parser_free ( $parser ) ;
fclose ( $fp ) ;
?>

grammar

 xml_set_unparsed_entity_decl_handler ( parser , handler )
parameter describe
parser Required. Specify the XML parser to use
Handler

Required. Specifies the function to be called when the XML parser encounters an external entity declaration with an NDATA declaration.

The function must accept six parameters:

  • $parser - Variable containing the XML parser that calls the handler
  • $entity_name - variable containing entity name
  • $base - The basis for parsing the system identifier (system_id) of an external entity. Currently, this is always an empty string
  • $system_id - System identifier for external entity
  • $public_id - Public identifier for external entity
  • $notation_name - the symbolic name of this entity
Similar Functions
Popular Articles