Php has an xml_parser_create () function for processing xml documents. let's take a look at this function. xml_parser_create () function creates an XML parser, which creates a new XML parser... php has an xml_parser_create () function for processing xml documents. let's take a look at this function.
The xml_parser_create () function creates an XML parser. this function creates a new XML parser and returns a resource handle that can be used by other XML functions.
Syntax: xml_parser_create (encoding)
Parameter description
Optional. specifies the output encoding.
The instance code is as follows:
some character data";$parser = xml_parser_create();xml_set_character_data_handler($parser, 'cdata_handler');if (xml_parse($parser, $xml, true)) print ("Your XML document is well-formed.");else print ("Your XML document is not well-formed.");xml_parser_free($parser);?>
Example 2: The code is as follows:
bar
Parse error in %s
(%s)", htmlspecialchars($xml) , xml_error_string(xml_get_error_code($p))));}xml_parser_free($p);?>
Example 3 code:
";$p = xml_parser_create();xml_set_processing_instruction_handler($p, 'pi_handler');if (!xml_parse($p, $xml, true)) die(sprintf("Parse error in %s
(%s)", htmlspecialchars($xml) , xml_error_string(xml_get_error_code($p))));else print ("XML processing complete.n");xml_parser_free($p);?>
Note:The optional parameter encoding is used in PHP 4 to specify the encoding method of the XML input to be parsed.
PHP 5 starts and automatically detects the input XML encoding. Therefore, the encoding parameter is only used to specify the encoding of the parsed output data.
In PHP 4, the default output encoding is the same as the input data encoding. if an empty string is passed, the parser will try to search for the first 3 or 4 bytes to determine the document encoding.
In PHP 5.0.0 and 5.0.1, the default output character encoding is ISO-8859-1, while PHP 5.0.2 and later versions are UTF-8, the parser supports the encoding of ISO-8859-1, UTF-8 and US-ASCII.
Article link:
Save this article for favorites!