There are two ways to instantiate a DOMIT! RSS document:
Instantiation and Parsing in a Single Line
In a single line of code, it is possible to both instantiate a DOMIT! RSS document and parse an RSS feed.
This abbreviated form is achieved by passing three parameters to the constructor: the feed url, (and optionally) the cache directory and expiry time:
//instantiate and parse RSS document
$rssdoc =& new xml_domit_rss_document('http://www.somesite.com/rss.xml',
'./', 3600);
A DOMIT! RSS Lite document can be instantiated in the same way:
//instantiate rss lite document
$rssdoc =& new xml_domit_rss_document_lite('http://www.somesite.com/rss.xml',
'./', 3600);
Instantiation and Parsing as Separate Actions
A DOMIT! RSS document can also be instantiated without immediately parsing an RSS feed. This approach allows you to set additional DOMIT! RSS properties, such as which caching system to use, or to parse an RSS string instead of an url.
To instantiate a DOMIT! RSS document without immediately parsing a feed, simply call the constructor without any parameters:
//instantiate an RSS document without parsing
$rssdoc =& new xml_domit_rss_document();
At this point, other parameters can be set for DOMIT! RSS. Parsing can then be performed using the loadRSS method:
$rssdoc =& new xml_domit_rss_document();
//...set some DOMIT! RSS properties...
$rssdoc->loadRSS('http://www.somesite.com/rss.xml');
setConnection
The setConnection method allows you to manually set the parameters of the http connection when a file is accessed remotely.
For example:
$rssdoc->setConnection('http://www.engageinteractive.com', '80');
setAuthorization
If basic HTTP authorization is required for the connection, the setAuthorization method allows you
to specify a user name and password:
$rssdoc->setAuthorization('johndoe', 'xyzzy');
setProxyConnection
The setProxyConnection method allows you to manually set the parameters of a proxy http connection:
$rssdoc->setProxyConnection('http://www.myProxy.com', '8080');
setProxyAuthorization
If basic HTTP authorization is required for the proxy connection, the setProxyAuthorization method allows you
to specify a user name and password:
$rssdoc->setProxyAuthorization('johndoe', 'xyzzy');
Substituting PEAR:Cache_Lite for php_text_cache
If you have the popular PEAR caching library Cache_Lite installed on your web server, you may prefer to use it instead of the default DOMIT! RSS caching system, php_text_cache
if so, then the method useCacheLite can be called to swap php_text_cache for Cache Lite.
It is called with four parameters:
doUseCacheLite - True to use Cache Lite
pathToLibrary - The absolute or relative path to the Cache Lite include file, e.g., './cache/Lite.php'
cacheDir - The directory in which cache file are to be stored
cacheTime - The expiry time in seconds of the cache
For example:
$rssdoc =& new xml_domit_rss_document();
$rssdoc->useCacheLite(true, './cache/Lite.php', './tmp/', 1800);
$rssdoc->loadRSS('http://www.somesite.com/rss.xml');
Parsing an RSS String instead of an Url
You have the option of parsing an RSS string instead of an url with DOMIT! RSS. This is done with the parseRSS method:
$rssdoc =& new xml_domit_rss_document();
$rssdoc->parseRSS('<rss version="0.92">...rss xml...</rss>');
|