Syntax:SimpleXMLElement simplexml_import_dom ($node, $class_name = "SimpleXMLElement")
Parameters :This function takes two parameters as above and described below:
- $node:This parameter contains a DOM element node.
- $class_name:is an optional parameter that contains the name of the class. If this parameter is used, then the simplexml_import_dom() function returns an object of the specified class. The class should extend the SimpleXMLElement class.
Return value:This function returns SimpleXMLElement on success or FALSE on error.The program below illustrates simplexml_import_dom() function in PHP:
Program :
// Create a DOMDocument instance
$dom
=
new
DOMDocument;
// Load XML document
$dom
-> loadXML (’< organization >
< name > GeeksforGeeks < / name >
Noida India
< contact >
< email > [email protected]< / email >
< mobile > + 91-987654321 < / mobile >
< / contact >
< / organization > ’
);
// Use the simplexml_import_dom() function to get
// SimpleXMLElement object from DOM node
$doc
= simplexml_import_dom (
$dom
);
// Show XML document content
var_dump (
$doc
-> contact [0] -> email );
var_dump (
$doc
-> contact [0] -> mobile);
?>
Exit:object (SimpleXMLElement ) # 3 (1) {[0] = > string (21) "[email protected]"} object (SimpleXMLElement) # 3 (1) {[0] = > string (13) "+ 91-987654321"}
Link: https://www.php.net/manual/en/function.simplexml-import-dom.php