Change language

PHP Xml_get_error_code () function

Syntax:
int xml_get_error_code (resource $xml_parser)
Parameters:This function takes one required parameter, $xml_parser . It defines the XML parser to be used.Return Value:This function returns the error code generated by the XML parser on success, or False on error.Notes :
  • This function is available for PHP 4.0.0 and above.
  • These examples may not work online the IDE. So, try running it on your local server or on the php hosts.
gfg.xml (Inappropriate tag error): xml version = "1.0" encoding = " utf-8 " ?> < user > < username > user123 < / username > < name > firstname lastname < / name > < phone > + 91-9876543210 < / phone > < detail > I am John Doe. Live in Kolkata, India. < / detail > < / users > Program 1:  
// XML file containing mismatch tags $xml_file = ’gfg.xml’ ;  
// Initialize the XML parser $xml_parser = xml_parser_create();  
// Open file in read mode $file_pointer = fopen ( $xml_file , ’ r’ );  
// Read data from the file stream while ( $xml_data = fread ( $file_pointer , 4096)) { // Parse the data block if (! xml_parse ( $xml_parser , $xml_data , feof ( $file_pointer ))) { // Display errors die ( print "ERROR:" . // Error string xml_error_string (xml_get_error_code ( $xml_parser )). "
Error Code: "
. // Error code xml_get_error_code ( $xml_parser ). "
Line: "
. // Line number where the error occurred xml_get_current_line_number ( $xml_parser ). "
Column: "
. // Number of the column where the error occurred xml_get_current_column_number ( $xml_parser ). "
Byte Index: "
. // Byte index where the current byte occurred xml_get_current_byte_index ( $xml_parser ). "
"
); } }  
// Free XML parser xml_parser_free ( $xml_parser );  
?>
Output:
ERROR: Mismatched tag Error Code: 76 Line: 7 Column: 13 Byte Index: 208
Geeks.xml file (error: string is not enclosed in double quotes): xml version = "1.0 encoding =" utf-8 "?> < user > < username > user123 < / username > < n ame > firstname lastname < / name > < phone > + 91-9876543210 < / phone > < detail > I am John Doe. Live in Kolkata, India. < / detail > < / user > Program 2:  
// XML file containing mismatch tags $xml_file = ’gfg.xml’ ;  
// Initialize the XML parser $xml_parser = xml_parser_create();  
// Open file in read mode $file_pointer = fopen ( $xml_file , ’ r’ );  
// Read data from the file stream while ( $xml_data = fread ( $file_pointer , 4096)) { // Parse the data block if (! xml_parse ( $xml_parser , $xml_data , feof ( $file_pointer ))) { // Display errors die ( print "ERROR:" . // Error string xml_error_string (xml_get_error_code ( $xml_parser )). "
Error Code: "
. // Error code xml_get_error_code ( $xml_parser ). "
Line: "
. // Line number where the error occurred xml_get_current_line_number ( $xml_parser ). "
Column: "
. // Number of the column where the error occurred xml_get_current_column_number ( $xml_parser ). "
Byte Index: "
. // Byte index where the current byte occurred xml_get_current_byte_index ( $xml_parser ). "
"
); } }  
// Free XML parser xml_parser_free ( $xml_parser );  
?>
Output:
ERROR: String not closed expecting "or’ Error Code: 34 Line: 1 Column: 38 Byte Index: 37
Link: https://www.php.net/manual/en/function.xml-get-error -code.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method