Change language

PHP Xml_error_string () function

Function xml_error_string()- is a built-in function in PHP that returns an XML parser error description for the generated error code.Syntax:
string xml_error_string (int $error_code)
Parameters:This function takes one required parameter, $error_code . It specifies the XML parser error code that is generated from the xml_get_error_code() function.Return Values:This function returns an XML parser error description for the specified error code generated from xml_get_error_code ( ) on success and False on error.Note.This function is available for PHP 4.0.0 and later.The following programs illustrate the xml_error_string ( ) in PHP:gfg.xml file: 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:  
// Invalid XML file $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 error 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
engineer.xml file: xml version = "1.0 encoding =" utf-8 "?> < user > < username > user123 < / username > < name > firstname las tname < / name > < phone > + 91-9876543210 < / phone > < detail > I am John Doe. Live in Kolkata, India. < / detail > < / user > Program 2:  
// Invalid XML file $xml_file = ’engineer.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 error 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: 36 Byte Index: 37
Link: https://www.php.net/manual/en/function.xml-error-string.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically