Skip to content
Related Articles

Related Articles

PHP | simplexml_import_dom() Function

View Discussion
Improve Article
Save Article
  • Last Updated : 29 Aug, 2019
View Discussion
Improve Article
Save Article

The simplexml_import_dom() function is in inbuilt function in PHP which is used to take a node of DOM document and convert it into a SimpleXML node.


SimpleXMLElement simplexml_import_dom( $node, $class_name = "SimpleXMLElement" )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $node: This parameter holds the DOM element node.
  • $class_name: It is optional parameter which holds the class name. If this parameter is used then simplexml_import_dom() function returns the object of specified class. The class should extend the SimpleXMLElement class.

Return Value: This function returns the SimpleXMLElement on success or FALSE on failure.

Below program illustrates the simplexml_import_dom() function in PHP:


// Create an instance of DOMDocument
$dom = new DOMDocument;
// Load XML document
$dom -> loadXML('<organization>
        <address>Noida India</address>
// Use simplexml_import_dom() function to get a
// SimpleXMLElement object from a DOM node
$doc = simplexml_import_dom($dom);
// Display the content of XML document


object(SimpleXMLElement)#3 (1) {
  string(21) ""
object(SimpleXMLElement)#3 (1) {
  string(13) "+91-987654321"


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!