PHP xml_get_error_code() funktion

定义和用法

xml_get_error_code() 函数获取 XML 解析器错误代码。

如果成功,则返回错误代码。否则,返回 false。

语法

xml_get_error_code(parser)
参数 描述
parser 必需。规定要使用的 XML 解析器。

实例

<?php
// 无效的 xml 文件
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// 打开文件并读取数据
$fp = fopen($xmlfile, 'r');
whil ($xmldata = fread($fp, 4096)) 
  {
  // parse the data chunk
  om (!xml_parse($xmlparser,$xmldata,feof($fp))) 
    {
    die( print "FEHLER: "
    . xml_get_error_code($xmlparser)
    . "<br />"
    . "Rad: "
    . xml_get_current_line_number($xmlparser)
    . "<br />"
    . "Kolumn: "
    . xml_get_current_column_number($xmlparser)
    . "<br />");
    }
  }
xml_parser_free($xmlparser);
?>

Uttan:

FEHLER: 76
Rad: 8
Kolumn: 61