Syntax:resource xml_parser_create_ns (string $encoding, string $separator )
Parameters:This function takes two parameters as above and described below:
- $encoding:this is an optional parameter. Defines the character encoding
- for input / output in PHP 4
- for output from PHP 5 only
- for 5.0.0 and 5.0.1 the default output encoding is ISO -8859-1
- from 5.0.2 the default is UTF-8 encoding
Possible $encoding values: ISO-8859-1, UTF-8 and US- ASCII. - $separator:This is an optional parameter. It defines the output delimiter for the tag name and namespace. Default value: ":".
Returned value: - On success:returns a handle to a resource to be used by some other XML functions.
- On Failure:returns FALSE.
Notes: - This feature is available for PHP 4.0.5 and above.
- These examples may not work in the online IDE. So, try running it on your local server or on the php hosts.
Below programs illustrate the xml_parser_create_ns() function in PHP:Program 1:
// Create XML parser with
// namespace support
$parser
= xml_parser_create_ns();
// Free the xml parser
xml_parser_free (
$parser
);
?>
Output:(no output)
Program 2:
// Create an XML parser
// with namespace support
$parser
= xml_parser_create_ns();
// Free the xml parser
$res
= xml_parser_free (
$parser
);
// Check if the parser has been created or not
if
(!
$parser
) {
echo
"error occured!"
;
}
else
{
echo
"parser with namespace support has successfully been created "
;
}
?>
Output:parser with namespace support has successfully been created
Link: https://www.php.net/manual/en/function.xml-parser-create-ns.php