PHPのxml_error_string()関数
定義と使用法
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リファレンス