Current Location: Home> Function Categories> xml_get_error_code

xml_get_error_code

Get XML parser error code
Name:xml_get_error_code
Category:XML parser
Programming Language:php
One-line Description:Returns the error code from the XML parser.

Definition and usage

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

Example

When an error occurs, return the error code, line number, and column number of the XML parser:

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

// Open the file and read the data
$fp = fopen ( $xmlfile , 'r' ) ;
while ( $xmldata = fread ( $fp , 4096 ) ) {
  // Analyze data blocks
  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 above code may be:

 ERROR : 76
Line : 5
Column : 41

grammar

 xml_get_error_code ( parser )
parameter describe
parser Required. Specifies the XML parser to use.
Similar Functions
Popular Articles