YouTip LogoYouTip

Func Simplexml Load File

[![Image 1: PHP SimpleXML Reference Manual]( PHP SimpleXML Reference Manual]( ## Example Convert an XML file to a SimpleXMLElement object, then output the keys and elements of the object: [Run Example Β»]( * * * ## Definition and Usage The simplexml_load_file() function converts a specified XML file into a SimpleXMLElement object. * * * ## Syntax simplexml_load_file(_file,classname,options,ns,is\_prefix_); | Parameter | Description | | --- | --- | | _file_ | Required. Specifies the path to the XML file. | | _classname_ | Optional. Specifies the class of the new object. | | _options_ | Optional. Specifies additional Libxml parameters. Set by specifying options as 1 or 0 (TRUE or FALSE, e.g., LIBXML_NOBLANKS(1)). Possible values: * LIBXML_COMPACT - Activate optimization of node configuration (may speed up application) * LIBXML_DTDATTR - Set default DTD attributes * LIBXML_DTDLOAD - Load external subset * LIBXML_DTDVALID - Validate with the DTD * LIBXML_NOBLANKS - Remove blank nodes * LIBXML_NOCDATA - Merge CDATA as text nodes * LIBXML_NOEMPTYTAG - Expand empty tags (e.g.,
to

), only valid in DOMDocument->save() and DOMDocument->saveXML() functions * LIBXML_NOENT - Substitute entities * LIBXML_NOERROR - Suppress error reports * LIBXML_NONET - Stop network access while loading documents * LIBXML_NOWARNING - Suppress warning reports * LIBXML_NOXMLDECL - Drop the XML declaration when saving a document * LIBXML_NSCLEAN - Remove redundant namespace declarations * LIBXML_PARSEHUGE - Set XML_PARSE_HUGE flag to relax any hardcoded limit from the parser. This affects limits like maximum depth of a document or the entity recursion, as well as limits of the size of text nodes. * LIBXML_XINCLUDE - Implement XInclude substitution * LIBXML_ERR_ERROR - Get recoverable errors * LIBXML_ERR_FATAL - Get fatal errors * LIBXML_ERR_NONE - Get no errors * LIBXML_ERR_WARNING - Get simple warnings * LIBXML_VERSION - Get libxml version (e.g., 20605 or 20617) * LIBXML_DOTTED_VERSION - Get dotted libxml version (e.g., 2.6.5 or 2.6.17) | | _ns_ | Optional. Specifies namespace prefix or URI. | | _is\_prefix_ | Optional. Specifies a boolean value. TRUE if _ns_ is a prefix, FALSE if _ns_ is a URI. Default is FALSE. | ## Technical Details | Return Value: | Returns a SimpleXMLElement object on success, FALSE on failure. | | --- | | PHP Version: | 5+ | * * * ## More Examples Assume we have the following XML file, "[note.xml](": Tove Jani Reminder Don't forget me this weekend! ## Example 1 Output the data of each element in the XML file: to . "
"; echo $xml->from . "
"; echo $xml->heading . "
"; echo $xml->body; ?> [Run Example Β»]( ## Example 2 Output the element name and data of each child node in the XML file: getName() . "
"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "
"; } ?> [Run Example Β»]( * * * [![Image 2: PHP SimpleXML Reference Manual]( PHP SimpleXML Reference Manual](
← Func Simplexml Load StringFunc Simplexml Import Dom β†’