Page 332 - Open Soource Technologies 304.indd
P. 332
Web Technologies-I
Notes Example shows how you would parse externally referenced XML documents. Define two
functions, create_parser( ) and parse( ), to do the actual work of creating and feeding the XML
parser. You can use them both to parse the top-level document and any documents included
via external references.
External entity reference handler.
function external_entity_reference($inParser, $inNames, $inBase, $inSystemID, $inPublicID)
{
if($inSystemID)
{
if(!list($parser, $fp) = create_parser($inSystemID))
{
echo “Error opening external entity $inSystemID \n”; return false;
}
return parse($parser, $fp);
}
return false;
}
Unparsed Entities
An unparsed entity declaration must be accompanied by a notation declaration:
<! DOCTYPE doc [<! NOTATION jpeg SYSTEM “image/jpeg”> <!ENTITY logo SYSTEM “php-
tiny.jpg” NDATA jpeg> ]>
Register a notation declaration handler with xml_set_notation_decl_handler( ):
xml_set_notation_decl_handler(parser, handler);
The handler will be called with five parameters:
my_notation_handler(parser, notation, base, system, public);
The base parameter is the base URI for resolving the identifier of the notation (which is currently
always empty). Either the system identifier or the public identifier for the notation will be set,
but not both.
Register an unparsed entity declaration with the xml_set_unparsed_entity_decl_handler( )
function:
xml_set_unparsed_entity_decl_handler(parser, handler);
The handler will be called with six parameters:
my_unp_entity_handler(parser, entity, base, system, public, notation);
The notation parameter identifies the notation declaration with which this unparsed entity is
associated.
Default Handler
For any other event, such as the XML declaration and the XML document type, the default
handler is called. To set the default handler, call the xml_set_default_handler( ) function:
326 LOVELY PROFESSIONAL UNIVERSITY