PHP xml_set_unparsed_entity_decl_handler()関数
例
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:
|
技術的な詳細
戻り値: | 成功するとTRUE。失敗するとFALSE |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPXMLパーサーリファレンス