[Gambas-user] New component gb.rss to generate and parse RSS documents

Adrien Prokopowicz adrien.prokopowicz at ...626...
Wed Apr 5 12:32:31 CEST 2017


Le Sun, 02 Apr 2017 18:07:26 +0200, Tobias Boege <taboege at ...626...> a  
écrit:

> Hello all,
>
> I wrote an RSS feed generator for one of my projects recently and could
> luckily complete also the parser before the new semester starts tomorrow.
> So you get a gb.rss component in the latest revision #8117.
>
> It should support all the things that are mentioned in the RSS 2.0
> specification here [1], but there are still some problems:
>
>   * The date conversion routines ignore timezones completely, because
>     I have no clue about working with timezones in Gambas.
>
>   * The strings you give to Rss* objects are put into the XML file
>     verbatim currently, which is not desirable if these strings
>     are HTML or some other things that confuse an RSS (XML) parser.
>     I guess those strings should be wrapped in a CDATA section.
>     I'd be grateful for a routine that tells me when to use CDATA.
>
> The attached project demonstrates the feed generator part. It takes the
> output of "ps", for the lack of a better data source, and turns it into
> an RSS feed, which is then offered through gb.httpd. I tested the  
> resulting
> feed with newsbeuter. Just load the feed, start some new programs and  
> then
> reload the feed.
>
> @Adrien or Fabien: While playing around with the XmlReader, I noticed  
> some
> problems. I tried to fix them to the best of my ability in #8116, but as
> always it would be better if you looked through the matter again.
>
> Regards,
> Tobi
>
> [1] http://cyber.harvard.edu/rss/rss.html
>

Hi Tobias,

First, thanks for the fixes. :)
The only thing that bothers me a bit is throwing an error if no attribute
is found when using the _get method on XmlReader.Node.Attributes.
It is made so it behaves like a Gambas collection (as XML Attributes can
be seen as a simple key-value store), so I think it is better to just
return Null in that case.

Other than that, it all looks good to me, so thanks again. :)

For your escaping problem, the XmlWriter.Element() now escapes the value
parameter so it is always safe to pass any String (all the other methods
dealing with text content already do that, like XmlWriter.Text() or
XmlNode.TextContent).

Currently, you can check if a string needs serialization by actually
serializing it and comparing it to the original string :

     If XmlNode.Serialize(Value) = Value Then ' [...]

It's not optimal if you're dealing with very large strings, but it works.
However, if some elements of the RSS document are likely to contain large  
HTML
or some other markup, I think it's better performance-wise to just
always wrap their contents in a CDATA node, as their contents are not  
checked.

As a side node, all these problems with the XmlReader & Writer are  
starting to
annoy me quite a bit (as those are mostly regressions). I think I should  
bring
back the unit testing library I wrote some time ago, and write some tests  
for
gb.xml locally at least.

Regards,

-- 
Adrien Prokopowicz




More information about the User mailing list