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

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically