API15

JFactory/getXMLParser

From Joomla! Documentation

< API15:JFactory

The "API15" 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]

Get an XML document

[<! removed edit link to red link >]

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

Syntax[edit]

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

object Parsed XML document object

Defined in[edit]

libraries/joomla/factory.php

Importing[edit]

jimport( 'joomla.factory' );

Source Body[edit]

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

Code Examples[edit]