PHP | simplexml_load_file() Function Last Updated : 02 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 $is_prefix = FALSE ) Parameters: This function accepts five parameters as mentioned above and described below: $filename: This parameter holds the path of filename. $class_name: It is optional parameter. Use of simplexml_load_file() function return the object of specified class. That class extends the SimpleXMLElement class. $options: It is optional parameter and used for additional Libxml parameter. $ns: This parameter holds the Namespace prefix or URI. $is_prefix: This parameter is set to TRUE if ns is a prefix and FALSE if it is URI. Its default value is FALSE. Return Value: This function returns an object of SimpleXMLElement class with properties containing the data held within the XML document, or FALSE on failure. Below program illustrates the simplexml_load_file() function in PHP: gfg.xml file: html <?xml version="1.0"?> <organization> <name>GeeksforGeeks</name> <address>Noida India</address> <contact> <email>[email protected]</email> <mobile>+91-987654321</mobile> </contact> </organization> Program: php <?php // Check file exist or not if (file_exists('gfg.xml')) { // If XML file exists then // load the XML file $xml_file = simplexml_load_file('gfg.xml'); // Display the content of XML file var_dump($xml_file); } else { exit('Fail to open the file'); } ?> Output: object(SimpleXMLElement)#1 (3) { ["name"]=> string(13) "GeeksforGeeks" ["address"]=> string(11) "Noida India" ["contact"]=> object(SimpleXMLElement)#2 (2) { ["email"]=> string(21) "[email protected]" ["mobile"]=> string(13) "+91-987654321" } } Reference: https://www.php.net/manual/en/function.simplexml-load-file.php Comment More infoAdvertise with us Next Article PHP | simplexml_load_file() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Php-SimpleXML Similar Reads 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 | simplexml_import_dom() Function 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 1 min read PHP | SimpleXMLElement children() Function Pre-requisite: Read XML BasicsThe SimpleXMLElement::children() function is an inbuilt function in PHP which returns children of a given node in a SimpleXML object. Syntax:  SimpleXMLElement SimpleXMLElement::children( $namespace, $is_prefix ) Parameter: This function accepts two parameters as ment 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 | SimpleXMLElement addChild() Function Pre-requisite: Read XML Basics The SimpleXMLElement::addChild() function is an inbuilt function in PHP which is used to add a child in a SimpleXML object. Syntax: SimpleXMLElement SimpleXMLElement::addChild($name, $value, $namespace); Parameter: This function accepts three parameters as mentioned ab 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 PHP | xml_parser_free() Function Pre-requisite: XML BasicsThe xml_parser_free() function is an inbuilt function in PHP which is used to free the XML parser. Syntax:  bool xml_parser_free( resource $parser ) Parameters: This function accepts single parameter $parser which is required. It specifies the reference of XML parser to fre 3 min read PHP | SimpleXMLElement attributes() Function Pre-requisite: Read XML BasicsThe SimpleXMLElement::attributes() function is an inbuilt function in PHP which is used to retrieve the attributes and its value from an XML tag in a SimpleXML object. Syntax:  SimpleXMLElement SimpleXMLElement::attributes( $namespace, $is_prefix ) Parameter: This fun 2 min read PHP | SimpleXMLIterator current() Function The SimpleXMLIterator::current() function is an inbuilt function in PHP which is used to return the current element as a SimpleXMLIterator object or NULL. Syntax: mixed SimpleXMLIterator::current( void ) Parameters: This function does not accepts any parameters. Return Value: This function returns t 1 min read Like