PHP | simplexml_import_dom() Function Last Updated : 29 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The simplexml_import_dom() function is an inbuilt function in PHP which is used to take a node of DOM document and convert it into a SimpleXML node. Syntax: 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: Program: php <?php // Create an instance of DOMDocument $dom = new DOMDocument; // Load XML document $dom -> loadXML('<organization> <name>GeeksforGeeks</name> <address>Noida India</address> <contact> <email>[email protected]</email> <mobile>+91-987654321</mobile> </contact> </organization>' ); // 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 var_dump($doc->contact[0]->email); var_dump($doc->contact[0]->mobile); ?> Output:object(SimpleXMLElement)#3 (1) { [0]=> string(21) "[email protected]" } object(SimpleXMLElement)#3 (1) { [0]=> string(13) "+91-987654321" } Reference: https://www.php.net/manual/en/function.simplexml-import-dom.php Comment More infoAdvertise with us Next Article PHP | SimpleXMLElement::getName() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Php-SimpleXML Similar Reads PHP | simplexml_load_file() Function The simplexml_load_file() function is an inbuilt function in PHP which is used to convert the well-formed XML document into the given file to an object. Syntax: SimpleXMLElement simplexml_load_file( string $filename, string $class_name = "SimpleXMLElement", int $options = 0, string $ns = "", bool $i 2 min read PHP | simplexml_load_string() Function Sometimes there is a need of parsing XML data in PHP. There are a handful of methods available to parse XML data. SimpleXML is one of them. Parsing an XML document means that navigating through the XML document and return the relevant pieces of information. Nowadays, a few APIs return data in JSON f 3 min read PHP | SimpleXMLElement asXML() Function Pre-requisite: Read XML The SimpleXMLElement::asXML() function is an inbuilt function in PHP which returns well-formed XML string from a SimpleXML object. Syntax: mixed SimpleXMLElement::asXML( $filename ) Parameters: This function accepts single parameter $filename which is optional. It specified t 2 min read PHP | SimpleXMLIterator next() Function The SimpleXMLIterator::next() function is an inbuilt function in PHP which is used to move the SimpleXMLIterator element to the next element. Syntax: void SimpleXMLIterator::next( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. 1 min read PHP | SimpleXMLElement::getName() Function Pre-requisite: Read XML basicsThe SimpleXMLElement::getName() function is an inbuilt function in PHP which returns the name of the xml element.Syntax:Â Â string SimpleXMLElement::getName( void ) Parameter: This function does not accept any parameter.Return Value: It returns a string which represents 2 min read PHP | SimpleXMLIterator key() Function The SimpleXMLIterator::key() function is an inbuilt function in PHP which is used to return the key of current element. Syntax: mixed SimpleXMLIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the XML tag name of the element SimpleXML 1 min read Like