Change language

PHP SimpleXMLElement getDocNamespaces () function

The SimpleXMLElement::getDocNamespaces() function is a built-in function in PHP that is used to retrieve namespaces declared in an XML document.Syntax:
 array SimpleXMLElement::getDocNamespaces ($recursive, $from_root)
Parameters:This function takes two parameters as above and described below:
  • $recursive:This is an optional and boolean parameter. The default is False. If True is passed as a parameter, then it recursively returns the namespaces in the parent as well as the child node. If set to False, then it only returns the namespaces of the parent node.
  • $from_root:This is an optional and boolean parameter. The default is correct. If set to True, it will validate namespaces from the root of the XML document. If set to False, it will check the namespaces under the child node.
Return Value:This function returns an array of namespace names with their corresponding URIs. Note.This function is available for PHP 5.1.2 and later.The following programs illustrate the SimpleXMLElement::getDocNamespaces() function in PHP: Program 1:  
// Load the XML document into $user $user = < < < XML < user xmlns: user_id = " http://engineerforengineer.org/user " > < single_user id = "1" > < user_id: id > 12345 < / user_id: id > < username > Geeks123 < / username > < name > GeeksforGeeks < / name > + 91-XXXXXXXXXX < / phone > < detail font-color = "blue" font-size = "24px" > Noida India < / detail > < / single_user > < single_user id = "2" > < user_id: id > 15980 < / user_id: id > < username > Geeks54321 < / username > < name > Geeks < / name > + 91-XXXXXXXXXX < / phone > < detail font-color = "blue" font-size = "24px" > Noida India < / detail > < / single_user >
< / user >
XML;  
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );  
// Retrieving namespaces $result = $xml -> getDocNamespaces();  
// Show output print_r ( $result );  
?>
Exit:
Array ([ user_id] = > http://engineerforengineer.org/user)
Program 2:  
// Load XML document into $user $user = < < < XML < user xmlns: user_id = " http://engineerforengineer.org/user " > < single_user id = " 1 " xmlns: name = " http://engineerforengineer.org/user/name " > < user_id: id > 12345 < / user_id: id > < username > rakesh123 < / username > < name: firstname > Rakesh < / name: firstname > < name: lastname > Kumar < / name: lastname > + 91-XXXXXXXXXX < / phone > < detail > Noida India < / detail > < / single_user > < single_user id = " 2 " xmlns: name = " http://engineerforengineer.org/user/name " > < user_id: id > 57833 < / user_id: id > < username > man123 < / username > < name: firstname > Manjeet < / name: firstname > < name: lastname > Singh < / name: lastname > + 91-XXXXXXXXXX < / phone > < detail > Kolkata, India < / detail > < / single_user > < single_user id = " 3 " xmlns: name = " http://engineerforengineer.org/user/name " > < user_id: id > 98944 < / user_id: id > < username > ak98 < / username > < name: firstname > Ak < / name: firstname > < name: lastname > Singh < / name: lastname > + 91-XXXXXXXXXX < / phone > < detail > Noida India < / detail > < / single_user > < / user >
XML;  
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );  
// Retrieving namespaces $result = $xml -> getDocNamespaces (TRUE);  
// Display the output print_r ( $result );  
?>
Exit:
Array ([ user_id] = > http://engineerforengineer.org/user [name] = > http://engineerforengineer.org/user/name)
Link: https://www.php.net/manual/en/simplexmlelement.getdocnamespaces.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