xml set unparsed entity decl handler in PHP

In this article I will explain how the xml_set_unparsed_entity_decl_handler() function can be used in PHP.
  • 1903

xml_set_unparsed_entity_decl_handler() function in PHP

  • The xml_set_unparsed_entity_decl_handler() function is specify functions to be called when the parser an unparsed entity in the XML document.
  • In xml_set_unparsed_entity_decl_handler() function handler parameter can also be an array containing a method name and an object reference.
  • The xml_set_unparsed_entity_decl_handler() function returns TRUE on success.
  • The xml_set_unparsed_entity_decl_handler() function returns FALSE on failure.

Syntax

xml_set_unparsed_entity_decl_handler(parser,handler)

Parameter

Parameter Description
parser This is the required parameter. It is specify for use to XML parser.
handler This is the required parameter. It is specify for a function to be called when the parser finds a notation declaration.

The xml_set_unparsed_entity_decl_handler() function specified by the "handler" parameter must have six parameters:

parameter Description
parser This is the required parameter. It is specify a variable containing the XML parser calling the handler.
name This is the required parameter. It is specify a variable containing the name of the entity.
base This is the required parameter. It is specify the base for resolving the system_id of the entity. Now, this is always NULL.
system_id This is the required parameter. It is specify a variable containing the system identifier for the entity.
public_id This is the required parameter. It is specify a variable containing the public identifier for the entity.
notation This is the required parameter. It is specify a variable containing the notation identifying the data type of the entity.

Example

The following example show to how the xml_set_unparsed_entity_decl_handler() function can be used in PHP.

<html>

<body>

<h3 style="color: skyblue;">xml_set_unparsed_entity_decl_handler() function example in PHP</h3>

    <?php

    $xml_parser=xml_parser_create();

    function char($xml_parser,$data)

    {

    echo $data;

    }

    function unparsed_ent_handler($xml_parser,$entname,$base,$sysID,$pubID,$notname)

    {

    print "$entname<br />";

    print "$sysID<br />";

    print "$pubID<br />";

    print "$notname<br />";

    }

    xml_set_character_data_handler($xml_parser,"char");

    xml_set_unparsed_entity_decl_handler($xml_parser,

    "unparsed_ent_handler");

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

    while ($data=fread($fp,4096))

    {

    xml_parse($xml_parser,$data,feof($fp)) or

    die (sprintf("XML Error: %s at line %d",

    xml_error_string(xml_get_error_code($xml_parser)),

    xml_get_current_line_number($xml_parser)));

    }

    xml_parser_free($xml_parser);

    ?>

</body>

</html>

 

Output

xml-set-unparsed-entity-decl-handler-php.gif
You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

© 2019 DotNetHeaven. All rights reserved.