API16:JFactory/getXML
From Joomla! Documentation
Description
Reads a XML file.
<! removed transcluded page call, red link never existed >
Syntax
static getXML($data, $isFile=true)
| Parameter Name | Default Value | Description |
|---|---|---|
| $data | $data Full path and file name. | |
| $isFile | true | false to load a string. |
Returns
mixed on success | false on error.
Defined in
libraries/joomla/factory.php
Importing
jimport( 'joomla.factory' );
Source Body
public static function getXML($data, $isFile = true)
{
jimport('joomla.utilities.xmlelement');
// Disable libxml errors and allow to fetch error information as needed
libxml_use_internal_errors(true);
if($isFile)
{
// Try to load the xml file
$xml = simplexml_load_file($data, 'JXMLElement');
}
else
{
// Try to load the xml string
$xml = simplexml_load_string($data, 'JXMLElement');
}
if( ! $xml)
{
// There was an error
JError::raiseWarning(100, JText::_('Failed loading XML file'));
if($isFile)
{
JError::raiseWarning(100, $data);
}
foreach(libxml_get_errors() as $error)
{
JError::raiseWarning(100, 'XML: '.$error->message);
}
}
return $xml ;
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples