Change language

PHP SimpleXMLElement children () function

The SimpleXMLElement::children() function is a built-in PHP function that returns the children of a given node in a SimpleXML object.Syntax:
 SimpleXMLElement SimpleXMLElement::children ($namespace, $is_prefix)
Parameter:This function takes two parameters as above and described below:
  • $namespace:This is an optional parameter. It defines the XML namespace.
  • $is_prefix:This is a boolean parameter and is optional. This is true if $namespace is a prefix and False if $namespace is a namespace URL. The default is False.
Returned value:This function returns a SimpleXMLElement object.Note.This the function is available in PHP 5.0.1 and later.The following programs illustrate the SimpleXMLElement::children() function in PHP:Program 1:this the program displays the value of the child node. < tbody>  
// Load XML document into $user $user = < < < XML < user > < username > Geeks123 < / username > < name > GeeksforGeeks < / name > + 91-XXXXXXXXXX < / phone >
Noida, UP, India
< / user >
XML;  
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );  
// Print child node foreach ( $xml -> children() as $child ) { echo "Child node:" . $child . "
"
; }  
?>
Output:
Child node: Geeks123 Child node: GeeksforGeeks Child node: + 91-XXXXXXXXXX Child node: Noida, UP, India
Program 2:This program displays the tag name and its value.  
// Load XML document into $user $user = < < < XML < user > < username > Geeks123 < / username > < name > GeeksforGeeks < / name > + 91-XXXXXXXXXX < / phone >
Noida, UP, India
< / user >
XML;  
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );  
// Print child node foreach ( $xml -> children() as $child ) { echo "Child node:" . $child -> getName() . "= >" . $child . "
"
; }  
?>
Output:
Child node: username = > Geeks123 Child node: name = > GeeksforGeeks Child node: phone = > + 91-XXXXXXXXXX Child node: address = > Noida, UP, India
Program 3:This program extracts the name of the child attribute with its value.  
// Load XML document into $user $user = < < < XML < user > < username font-color = "green" font = "awsome-fonts" font-size = "72px" > Geeks123 < / username > < name font-color = " blue " font = "awsome-fonts" font-size = " 36px " > GeeksforGeeks < / name > " blue " type = "number" font = " awsome-fonts " font-size = " 24px " > + 91-XXXXXXXXXX < / phone >
" blue " font = "awsome-fonts" font-size = " 24px " > Noida, UP, India
< / user >
XML;  
// Load the string as a simple xml object $xml = simplexml_load_string ( $user );  
// Print children attribute foreach ( $xml -> children() as $child ) { echo "Child name:" . $child -> getName() . "= >" . $child . "
"
; foreach ( $child -> attributes() as $key = > $value ) echo " parameter:" . $key . "= >" . $value . "
"
; }  
?>
Output:
Child name: username = > Geeks123 parameter: font-color = > green parameter: font = > awsome-fonts parameter: font-size = > 72px Child name: name = > GeeksforGeeks parameter: font-color = > blue parameter: font = > awsome-fonts parameter: font-size = > 36px Child name: phone = > + 91-XXXXXXXXXX parameter: font-color = > blue parameter: type = > number parameter: font = > awsome-fonts parameter: font-size = > 24px Child name: address = > Noida, UP, India parameter: font-color = > blue parameter: font = > awsome-fonts parameter: font-size = > 24px
Link: https://www.php.net /manual/en/simplexmlelement.children.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

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