Change language

PHP SimpleXMLElement getNamespaces () function

Function SimpleXMLElement::getNamespaces() - it is a built-in function in PHP that is used to extract namespaces declared in an XML document.Syntax:
array SimpleXMLElement::getNamespaces ($recursive)
Parameter:This function takes one parameter $recursive,which is optional. Its default value is - FALSE. If True is passed, it returns a recursive namespace in the parent and child nodes. If set to False, then it only returns the namespaces of the parent 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::getNamespaces() function in PHP:Program 1:  
// Load 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 -> getNamespaces (1);  
// 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 -> getNamespaces (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.getnamespaces.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