Lasso Soft Inc. > Home

  • Articles

RSS Data Source Examples and Update

Taken from the tip of the week for January 4, 2008, this article includes an update to the RSS data source and examples of how the RSS data source can be used on your Web site.

The tip includes a custom data source which allows RSS feeds to be treated as a data source. The items in the feed can be displayed using normal [Inline] ... [/Inline] and [Field] tags. Also includes an [RSS_Parser] data type.

Introduction

In Lasso 8.5 data sources can be written entirely within LassoScript code. This tip includes a data source which parses RSS feeds and makes them available for display through normal [Inline] ... [/Inline] and [Field] tags.

Note - Lasso 8.5.5 or higher is required to run the code in this tip.

The data source was introduced in an earlier tip of the week. Please read that tip for background information about the data source and the [RSS_Parser] type which is included.

Download and Installation

The source file for the RSS data source can be downloaded using the following link. The "rss_datasource.lasso" file should be placed into either the global "LassoStartup" folder or a specific site's "LassoStartup" folder. The Lasso site must be restarted before the data source can be used.

RSS Datasource.lasso 

RSS Example.lasso 

Data Source Change Notes

The RSS data source now supports simple search terms and other inline parameters.

Searching - The default 'items' table supports searching using standard Lasso syntax. The available field names include title, description, and pubDate. The full list can be seen using [Field_Names]. Supported operators include bw, cn, eq, ew, lt, lte, gt, gte, nbw, ncn, neq, new, nrx, rx. This search would return only items with a description starting with '[Announce]'.

-BW, 'description'='[Announce]',

The value for pubDate searches should be a date object. This search would return only items from 2008.

-GTE, 'pubDate'=date('1/1/2008'),

Comparisons to NULL allow items with or without a specified element to be returned. Most comparisons are performed as strings so less than and greater than will be alphabetical comparisons. An AND search will always be performed. Logical operators are not supported.

Sorting - The -SortField parameter can be used to specify what field to sort the RSS feed by. By default the items are reported in the same order they were in the original feed. The -SortOrder parameter can be set to 'ascending' (default) or 'descending'.

-SortField='pubDate', -SortOrder='ascending',

Return Field - The -ReturnField parameter can be used to limit the fields which are returned by the data source. This can be useful if you are using common display code with different data sources.

-ReturnField='description', -ReturnField='title', -ReturnField='pubDate'

Max Records and Skip Records - The -MaxRecords and -SkipRecords parameters can be used to page through an RSS feed. Note that since RSS feeds are frequently updated the items in the RSS feed may change between loads.

-MaxRecords=25

Examples

The following inline displays only elements from the Lasso Talk RSS feed which contain the term "RSS" in their description.

[Inline(-Search,
      -Host=Array(-datasource='rss_datasource'),
      -Database='http://www.listsearch.com/lasso/rss.lasso',
      -Op='cn', 'description'='RSS')]
    [Records]
      <a href="[Field('link')]">[Field('title')]</a>
      <br />[Field('pubdate')]
      <br />[Field('description')]
      <hr />
    [/Records]
  [/Inline]

The following inline displays the first couple elements from an RSS feed using [Records_Array]. Only the link, title, and pubDate of the items is returned.

[Inline(-Search,
      -Host=Array(-datasource='rss_datasource'),
      -Database='http://www.listsearch.com/lasso/rss.lasso',
      -MaxRecords=2,
      -ReturnField='link', -ReturnField='title', -ReturnField='pubdate')]
    [Records_Array]
  [/Inline]

array: (array: (http://www.listsearch.com/lasso/Message/index.lasso?233177), (01/05/2008 15:57:07 GMT), (Lightweight RSS Ticker in Jquery)), (array: (http://www.listsearch.com/lasso/Message/index.lasso?233176), (01/05/2008 14:20:46 GMT), (Re: [TotW] RSS Data Source and Parser))

The following inline displays a feed with the newest items first.

[Inline(-Search,
      -Host=Array(-datasource='rss_datasource'),
      -Database='http://rss.cnn.com/rss/cnn_topstories.rss',
      -SortField='pubDate', -SortOrder='descending',
      -MaxRecords='all')]
    [Records]
      <a href="[Field('link')]">[Field('title')]</a>
      <br />[Field('pubdate')]
      <br />[Field('description')]
      <hr />
    [/Records]
  [/Inline]

Implementation

See the source of the "rss_datasource.lasso" file for full details.

The implementation of inline parameters is contained within the [RSS_Parser->Items] tag. The [RSS_Parser->Filter] tag is used to apply a single search term to the current items array, removing any items which do not match. If a sort field is specified then a sort array is created, sorted, and the items array is re-ordered to match. Max records and skip records are implemented using [Array->Merge] to pull the selected subset out of the items array. Finally, return field simply removes any fields which are not named from each map in the items array.

More Information

More information about all of the tags used in this tip of the week can be found in the Lasso 8.5 Language Guide or in the online Lasso Reference 

Author: Fletcher Sandbeck
Created: 14 Feb 2008
Last Modified: 16 Mar 2011

Comments

No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft