API16

JFactory/getXML

From Joomla! Documentation

< API16:JFactory
Revision as of 17:47, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Reads a XML file. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span> {...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Reads a XML file.

[Edit Descripton]

Template:Description:JFactory/getXML

Syntax[edit]

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[edit]

mixed on success | false on error.

Defined in[edit]

libraries/joomla/factory.php

Importing[edit]

jimport( 'joomla.factory' );

Source Body[edit]

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 ;
}

[Edit See Also] Template:SeeAlso:JFactory/getXML

Examples[edit]

<CodeExamplesForm />