xml_set_notation_decl_handler
设置表示法声明处理程序
此函数适用于PHP 4及以上版本。
xml_set_notation_decl_handler函数是PHP的XML扩展中的一个函数,用于设置在解析XML文档时,当遇到DTD声明中定义的实体或符号时的回调函数。此函数用于通知解析器如何处理这种声明。
bool xml_set_notation_decl_handler ( resource $parser, callable $handler )
如果成功,返回true;如果失败,返回false。
function notation_decl_handler($notation_name, $public_id, $system_id) {
echo "Notation Name: " . $notation_name . "\n";
echo "Public ID: " . $public_id . "\n";
echo "System ID: " . $system_id . "\n";
}
<p>$parser = xml_parser_create();<br>
xml_set_notation_decl_handler($parser, "notation_decl_handler");</p>
<p>$xml_data = '</p>
<!DOCTYPE note [
<!NOTATION pdf PUBLIC "-//Adobe//PDF 1.3//EN" "http://www.adobe.com/pdf/1.3">
<p>]><br>
<note><br>
<to>Tove</to><br>
<from>Jani</from><br>
<heading>Reminder</heading></p>
<body>Don't forget me this weekend!</body>
</note>';
<p>xml_parse($parser, $xml_data);<br>
xml_parser_free($parser);
在上面的示例中,我们定义了一个回调函数"notation_decl_handler",它接受三个参数:符号名称、公共标识符和系统标识符。然后,我们使用xml_set_notation_decl_handler来注册该回调函数。接下来,创建了一个包含DTD声明的XML数据,并将其传递给XML解析器进行解析。每当解析器遇到DTD声明时,回调函数会被调用并打印出相关信息。