PHP | xml_parser_create_ns() Function

The xml_parser_create_ns() function is an inbuilt function in PHP which is used to create an XML parser with namespace support and returns the resource handle.

Syntax:

resource xml_parser_create_ns( string $encoding, string $separator )

Parameters: This function accepts two parameters as mentioned above and described below:



  • $encoding: It is optional parameter. It specifies character encoding
    • for input/output in PHP 4
    • only for output from PHP 5
    • for 5.0.0 and 5.0.1 default output charset is ISO-8859-1
    • from 5.0.2 default output charset is UTF-8

    The possible values of $encoding are ISO-8859-1, UTF-8 and US-ASCII.

  • $separator: It is optional parameter. It specifies the output separator for tag name and namespace. Its default value is ” : “.

Return Value:

  • On Success: It returns a resource handle which is to be used by some other XML functions.
  • On Failure: It returns FALSE.

Note:

  • This function is available for PHP 4.0.5 and newer version.
  • These examples may not work on online IDE. So, try to run it on local server or php hosted servers.

Below programs illustrate the xml_parser_create_ns() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create an XML parser with
// namespace support
$parser = xml_parser_create_ns();
  
// Free the xml parser
xml_parser_free($parser);
  
?>

chevron_right


Output:

(no output)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Createing an XML parser
// with namespace support
$parser = xml_parser_create_ns();
  
// Free the xml parser
$res = xml_parser_free($parser);
  
// Check parser is created or not
if(!$parser) {
    echo "error occured!";
}else {
    echo "parser with namespace support has successfully been created";
}
?>

chevron_right


Output:

parser with namespace support has successfully been created

Reference: https://www.php.net/manual/en/function.xml-parser-create-ns.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.