PHP SimpleXMLElement :: getName () function

Function SimpleXMLElement::getName() - it is a built-in function in PHP that returns the xml element name.Syntax:
string SimpleXMLElement::getName (void)
Parameter:This function takes no parameters.Return Value:Returns a string that represents the XML element name of the SimpleXMLElement .Note.This function is available in PHP 5.1.3 and later.The following programs illustrate the SimpleXMLElement::getName() function in PHP:Example 1:
// Load the XML document into $user $user = < < < XML < user > < username > Geeks123 < / username > < name > GeeksforGeeks < / name > < phone > + 91-XXXXXXXXXX < / phone > < detail font-color = "blue" font-size = "24px" > Noide India < / detail > < / user >
XML;
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );
// Show element name echo "Base tag name:" . $xml -> getName(). "< br >" ; foreach ( $xml -> children() as $child ) { echo "child node:" . $child -> getName() . "=" . $child . "< / br >" ; }
?>
Output: Example 2:
// Loading XML document in $user $user = < < < XML < user > < username > Geeks123 < / username > < name > GeeksforGeeks < / name > < phone > + 91-XXXXXXXXXX < / phone > < detail font-color = "blue" font-size = "24px" > Computer science portal < / detail >
< city > Noida < / city > < country > India < / country > < / address > < / user >
XML;
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );
// Recursive function is called getname_rec ( $xml , 0);
// Definition of the getname_rec() function function getname_rec ( $xml , $depth ) { print_space ( $depth ); echo " tag name: " . $xml -> getName(). "< br >" ; foreach ( $xml -> children() as $child ) { if ( $child -> count () > 0) { // If any child of the current node exists getname_rec ( $child , $depth + 1); } else { // If there is no child of the current node print_space ( $depth ) ; echo "child node:" . $child -> getName() . "=" . $child . "< / br >" ; } } }
// Function to print 3X $i number of spaces function print_space ( $i ) { for ( $x = 0; $x < $i * 3; $x ++) { echo " " ; } }
?>
Output: Link: https://www.php.net/manual/en/simplexmlelement.getname.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