目录

PHP xml_set_unparsed_entity_decl_handler() 函数

❮ PHP XML 解析器参考

示例

创建 XML 解析器,设置字符数据处理程序,设置未解析的实体声明处理程序,并解析 XML 文档:

<?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 up unparsed 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 at line %d",
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
fclose($fp);
?>


定义和用法

xml_set_unparsed_entity_decl_handler() 函数指定当解析器解析 XML 文档中的未解析实体时要调用的函数。

笔记:处理程序参数也可以是包含对象引用和方法名称的数组。

语法

xml_set_unparsed_entity_decl_handler( parser, handler)

参数值

Parameter Description
parser Required. Specifies the XML parser to use
handler Required. Specifies a function to be called if the XML parser encounters an external entity declaration with an NDATA declaration. The function must accept six parameters:
  • $parser - A variable containing the XML parser calling the handler
  • $entity_name - A variable containing the name of the entity
  • $base - The base for resolving the system identifier (system_id) of the external entity. Currently, this is always an empty string
  • $system_id - The system identifier of the external entity
  • $public_id - The public identifier of the external entity
  • $notation_name - The name of the notation of this entity


技术细节

返回值: 成功则为真。失败时为 FALSE
PHP 版本: 4.0+

❮ PHP XML 解析器参考