User Tools

Site Tools


Sidebar

Network and communication

k24:k24.12:start

24.12.0 Component WebFeed (gb.web.feed)

The component gb.web.feed - WebFeed for short - corresponds to the RSS 2.0 specification, which you can also read about at https://cyber.harvard.edu/rss/rss.html.

Areas of application for RSS are, for example, news sites, blogs or podcasts whose contents are updated regularly - often several times a day. In addition to the RSS document structure and the terminology of RSS, you should also know XML as the basis of structured data in order to be able to use the WebFeed component successfully.

An RSS file is an XML file consisting of several 'channels', which in turn consist of 'entries'. Each entry is a unit that summarises a `news item` or whatever the content of the feed is. The gb.web.feed component can both read and write RSS files and supports images, media attachments, text input elements and cloud tags.

  • The way to read an RSS feed is to create an RSS object, fill it with content and then parse it for the content you want to read. The next step is to then display the RSS feed data stored in a suitable format.
  • You write RSS files via an object-oriented interface by creating an RSS object, assigning it channel objects (Channels) and in turn creating entry objects (Items) in them and filling them with data. The result is an XML document.

Example of an excerpt from an RSS feed:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="/resources/xsl/rss2.jsp" type="text/xsl"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
...
  <item>
    <title>Corona-Pandemie ...</title>
    <link>https://www.....html</link>
    <pubDate>Sun, 11 Oct 2020 10:14:50 +0200</pubDate>
    ...
    <description>Die gemeldeten Infektionszahlen bleiben hoch. ...</description>
  </item>
...
</channel>
</rss>

24.12.0.1 Class Rss

This class represents an RSS document. Its properties are those of its individual elements. It behaves like a read-write array of RssItem objects.

  • You can use the class Rss to either read the content of an RSS document or to create an RSS document.
  • You can create an object of the class Rss - as with all other classes of the WebFeed component.

In the following example, the RSS feed data in XML format (→ Chapter 18.12.5 RSS reader) of a website is read out. Here is the abbreviated RSS XML source text excerpt for an entry:

<item>
  <title>DFB-Elf ...</title>
  <link>http://www.unsersport.de/fussball/nationalmannschaft/...html</link>
  <description>Die Nationalmannschaft gewinnt in Krusemark mit 12:0 gegen den SV Heidesand.</description>
</item>

You can go through the individual RSS entries in the order in which they appear in the RSS document:

Dim hRss As Rss
Dim hRssItem As RssItem

For Each hRssItem In hRss
  ...
Next

The following source code returns an RssItem at the `index` RSS document position:

Dim hRss As Rss
Dim hRssItem As RssItem

hRssItem = hRss [ Index As Integer ]

So you replace an existing item in the RSS document at the position `Index`:

Dim hRss As Rss
Dim hRssItem As RssItem

hRss [ Index As Integer ] = hRssItem
  • When asked what the many classes of the gb.web.feed component do, the following applies across the board:
  • Each class represents a specific part of an RSS document as an object. What this means in concrete terms can be found in the RSS specification mentioned above.
  • The WebFeed component implements a so-called document-object model.. On the one hand, this means that the document is parsed and the individual components can be manipulated as Gambas objects.
  • Or you create a tree of Gambas objects with the help of the RSS classes and write a valid RSS XML document from it. To do this, add your elements in order. The use of the three properties title, link and description of the class Rss is mandatory to create an RSS document. All other properties are optional. Then call the method ToString() to get the XML document string.

The Rss class has these properties:

PropertyDataTypeDescription
TitleStringThe name or title of the feed.
LinkStringThe URL to the website corresponding to this feed.
DescriptionStringProvides a description of the content of the feed.
CategoriesRssCategory[]Represents an array of categories for this feed.
CloudRssCloudProvides a description of an associated cloud service.
CopyrightStringCopyright notice for the content of the feed.
CountIntegerReturns the number of RssItems in the RSS document.
DocsStringReturns a link to the RSS specification to inform about what an RSS file is, if the documentation exists.
GeneratorStringNames the program used to generate the feed.
ImageRssImageReturns an image associated with the feed.
LanguageStringThe language in which the content of the feed is written. Use a value defined according to https://cyber.harvard.edu/rss/languages.html !
LastBuildRssDateThe date and time zone of the last change of the feed content. If the property is not set, the default is the time when the XML document was written in the local time zone.
ManagingEditorStringEmail address of the managing (feed) editor.
PubRssDatePublication date/time zone of the feed. For example, a newspaper with daily publication would change a feed at least once a day. If the default is not set, it defaults to the time the XML document was written in the local time zone.
RatingStringPICS rating of the feed - if it exists.
SkipDaysInteger[ ]A hint for news aggregators. It specifies a number of days of the week (gb.Monday, gb.Tuesday, etc.) when no new content is expected in the feed. A client can ignore this setting. However, it can also use it to save traffic. You can only specify up to 7 skip days.
SkipHoursInteger[ ]A hint for news aggregators. It specifies a number of hours in the range 0 to 23 in which no new content is expected in the feed. A client can ignore this setting, but can also use it to save traffic. You can only specify up to 24 skip hours.
TextInputRssTextInputDescribes a text input field to be displayed with the feed.
TTLInteger'Time To Live' specifies how long the content of the feed may be cached. The unit of TTL is minutes.
WebMasterStringEmail address of the webmaster.

Table 24.12.0.1 : Properties of the class Rss

24.12.0.2 Methods

The class Rss has these methods:

MethodReturnTypeDescription
Sub Add ( Item As RssItem [ , Index As Integer ] )-Adds an Rss item to the document. If the index is specified, the item is inserted at the specified position in the array of items. By default it is inserted at the end.
Sub Clear ( )-All properties of the Rss object are set to zero and the element array is emptied completely.
Sub FromString ( argData As String )-Reads the RSS document in XML format specified under 'argData' and fills the properties of this Rss object.
Function ToString ( )StringConverts an Rss object into an XML document and returns its content.
Sub Remove ( Index As Integer [ , Length As Integer ] )-Removes as many Rss entries from the element array as specified by 'Length' - starting at the position 'Index'. By default, 'Length' is equal to 1.
Sub Reverse ( )-Reverses the order of the Rss entries in the element array.
Sub Sort ( [ Mode As Integer ] )-Sorts the Rss entries according to their date. You can select the mode as gb.Ascent or gb.Descent. The default is descending sort so that the newest items are first in the document.

Table 24.12.0.2 : Methods of the class Rss

24.12.0.3 Class RssCategory

Properties of the class:

PropertyData typeDescription
CategoryStringThe string describes the category. Use slashes as separators to structure categories hierarchically.
DomainStringThe URL to the website corresponding to this feed. The category domain is an ID or URL to a category description.

Table 24.12.0.3 : Properties of the RssCategory class.

24.12.0.4 Class RssCloud

The class has the following three integer constants:

RssCloud.XmlRpc (0)RssCloud.Soap (1)RssCloud.HttpPost (2).

These are the properties of the class:

PropertyData typeDescription
DomainStringDomain name of the application server.
PathStringThe script path on the server.
ProtocolInteger`Protocol` represents the RSSCloud protocol to be used. Optionally XmlRpc, Soap or HttpPost.
RegisterProcedureStringName of the registration procedure to be invoked on the server side.

Table 24.12.0.4 : Properties of the RssCloud class.

24.12.0.5 Class RssDate

You can create the class:

Dim hRssDate As RssDate
hRssDate = New RssDate ( [ Date As Date, Zone As String ] )

This class has only two properties:

PropertyData typeDescription
DateDate is the date represented by this object.
ZoneStringZone is the time zone - relative to which the date was inserted. Example: Sun, 11 Oct 2020 10:14:50 +0200 .

Table 24.12.0.5 : Properties of the RssDate class

24.12.0.6 Class RssEnclosure

The class has these three properties:

PropertyDataTypeDescription
LengthLongThe length of the attached file in bytes.
TypeStringReturns or sets the MIME type of the file.
UrlStringThe URL of the attached file.

Table 24.12.0.6 : Properties of the class RssEnclosure

24.12.0.7 Class RssGuid

GUID stands for 'Globally Unique IDentifier' - as a globally unique identifier for a particular feed item/article. The class has these properties:

PropertyDataTypeDescription
GuidStringGUID string. The value is a URL.
IsPermaLinkBooleanReturns whether this GUID is a permalink or sets a matching truth value. The default value of this property is True.

Table 24.12.0.7 : Properties of the class RssGuid

24.12.0.8 Class RssImage

The class RssImage has these properties:

PropertyData typeDescription
DescriptionStringIf the feed is rendered as HTML, this string shall become the title attribute of the link rendered around the image.
HeightIntegerThe height of the image. The maximum height is 400 pixels. The default value is 31 pixels.
WidthIntegerThe width of the image. The maximum width is 144 pixels. The default value is 88 pixels.
LinkStringThe URL of the website to which the feed belongs. If the feed is rendered as HTML, the RssImage becomes a link to this website.
Title StringAn image title. It is to be used as the alt attribute of the HTML tag when the feed is rendered as HTML.
UrlStringThe URL of the image file. The specification requires that it be a GIF, JPEG or PNG file.

Table 24.12.0.8 : Properties of the RssImage class.

24.12.0.9 Class RssItem

These are the properties of the class RssItem:

PropertyData typeDescription
AuthorStringAuthor's email address.
CategoriesRssCategory[ ]An array of categories for this entry.
CommentsStringA URL pointing to a comments page for this entry.
DescriptionStringA summary of the item. You can also use HTML.
EnclosureRssEnclosureDescribes a media attachment for this entry.
GuidRssGuidA globally unique identifier for this article, for example a permalink to the full content of the article on your website.
LinkStringA link to the website that contains the full content.
PubRssDatePublication date/time zone of the article. If this option is not set, the default is the time when the XML document was written in the local time zone.
SourceRssSourceUse this property if an item comes from another RSS feed, so as to link to the original feed.
TitleStringThe title of the entry.

Table 24.12.0.9 : Properties of the class RssItem

24.12.0.10 Class RssSource

These are the two properties of the class RssSource:

PropertyData typeDescription
SourceStringThe feed title of the RSS feed of the specified source.
UrlStringLink to the XML document of the external RSS feed.

24.12.0.11 Class RssTextInput

The class describes a text input field that can optionally be displayed with the feed to implement a comment function. The specification provides that RSS generators allow the creator of an RSS document to create text input fields and a corresponding CGI script on the domain. A reader of the RSS feed can thus - if his RSS feed client supports it - send a text directly from the display of the feed to the generator.

The class has these properties:

PropertyData typeDescription
DescriptionStringExplanation of the purpose of the input field.
LinkStringLink to the CGI script that processes the input.
NameStringName of the input field, for use by the CGI script to which the input is sent.
TitleStringThe label of the submit button next to the input field.

Table 24.12.0.11 : Properties of the class RssTextInput

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k24/k24.12/start.txt · Last modified: 16.08.2022 (external edit)

Page Tools