Actions

API15

JFactory/getXMLParser

From Joomla! Documentation

< API15:JFactory
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Get an XML document

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

& getXMLParser($type= 'DOM', $options=array())
Parameter Name Default Value Description
$type 'DOM' The type of xml parser needed 'DOM', 'RSS' or 'Simple'
$options array() boolean ['lite'] When using 'DOM' if true or not defined then domit_lite is used string ['rssUrl'] the rss url to parse when using "RSS" string ['cache_time'] with 'RSS' - feed cache time. If not defined defaults to 3600 sec

Returns

object Parsed XML document object

Defined in

libraries/joomla/factory.php

Importing

jimport( 'joomla.factory' );

Source Body

function &getXMLParser( $type = 'DOM', $options = array())
{
       $doc = null;
 
       switch (strtolower( $type ))
       {
               case 'rss' :
               case 'atom' :
               {
                       if (!is_null( $options['rssUrl'] ))
                       {
                               jimport ('simplepie.simplepie');
                               if(!is_writable(JPATH_BASE.DS.'cache')) {
                                       $options['cache_time'] = 0;
                               }
                               $simplepie = new SimplePie(
                                       $options['rssUrl'],
                                       JPATH_BASE.DS.'cache',
                                       isset( $options['cache_time'] ) ? $options['cache_time'] : 0
                               );
                               $simplepie->handle_content_type();
                               if ($simplepie->init()) {
                                       $doc = $simplepie;
                               } else {
                                       JError::raiseWarning( 'SOME_ERROR_CODE', JText::_('ERROR LOADING FEED DATA') );
                               }
                       }
               }       break;
 
               case 'simple' :
               {
                       jimport('joomla.utilities.simplexml');
                       $doc = new JSimpleXML();
               }       break;
 
               case 'dom'  :
               default :
               {
                       if (!isset($options['lite']) || $options['lite'])
                       {
                               jimport('domit.xml_domit_lite_include');
                               $doc = new DOMIT_Lite_Document();
                       }
                       else
                       {
                               jimport('domit.xml_domit_include');
                               $doc = new DOMIT_Document();
                       }
               }
       }
 
       return $doc;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />