PHP xml_get_error_code() Function

❮ PHP XML Parser Reference

Example

On error, return the XML parser error code, line number and column number:

<?php
// Invalid xml file
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();

// Open the 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_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);
?>

The output of the code above could be:

ERROR: 76
Line: 5
Column: 41

Definition and Usage

The xml_get_error_code() function returns the XML parser error code.

Syntax

xml_get_error_code(parser)

Parameter Values

Parameter Description
parser Required. Specifies the XML parser to use

Technical Details

Return Value: The error code on success. FALSE on failure
PHP Version: 4.0+

❮ PHP XML Parser Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.