PHP xml_error_string()関数
完全な PHP XML リファレンスマニュアル
定義と使用法
xml_error_string() 関数は XML パーサーのエラー説明を取得します。
成功した場合、この関数はエラー説明を返します。失敗した場合は FALSE を返します。
構文
xml_error_string(errorcode)
| パラメータ | 説明 |
|---|---|
| errorcode | 必須。使用するエラーコードを指定します。このエラーコードは xml_get_error_code() 関数の戻り値です。 |
例
<?php
//invalid xml file
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// open a file and read data
$fp = fopen($xmlfile, 'r');
while ($xmldata = fread($fp, 4096))
{
// parse the data chunk
if (!xml_parse($xmlparser,$xmldata,feof($fp)))
{
die( print "ERROR: "
. xml_error_string(xml_get_error_code($xmlparser))
. "<br />"
. "Line: "
. xml_get_current_line_number($xmlparser)
. "<br />"
. "Column: "
. xml_get_current_column_number($xmlparser)
. "<br />");
}
}
xml_parser_free($xmlparser);
?>
//invalid xml file
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// open a file and read data
$fp = fopen($xmlfile, 'r');
while ($xmldata = fread($fp, 4096))
{
// parse the data chunk
if (!xml_parse($xmlparser,$xmldata,feof($fp)))
{
die( print "ERROR: "
. xml_error_string(xml_get_error_code($xmlparser))
. "<br />"
. "Line: "
. xml_get_current_line_number($xmlparser)
. "<br />"
. "Column: "
. xml_get_current_column_number($xmlparser)
. "<br />");
}
}
xml_parser_free($xmlparser);
?>
上記のコードの出力は次のとおりです:
ERROR: Mismatched tag
Line: 5
Column: 41
Line: 5
Column: 41
完全な PHP XML リファレンスマニュアル その他の拡張機能