XML::RSSLite(3pm)

XML::RSSLite3pm

Lightweight, "relaxed" rss (and xml-ish) parser

Usage

  use XML::RSSLite;
  parseRSS(\%result, \$content);
  print "=== Channel ===\n",
        "Title: $result{'title'}\n",
        "Desc:  $result{'description'}\n",
        "Link:  $result{'link'}\n\n";
  foreach $item (@{$result{'items'}}) {
  print "  --- Item ---\n",
        "  Title: $item->{'title'}\n",
        "  Desc:  $item->{'description'}\n",
        "  Link:  $item->{'link'}\n\n";
  }

Overview

This module attempts to extract the maximum amount of content from available documents, and is less concerned with XML compliance than alternatives. Rather than rely on XML::Parser, it uses heuristics and good old-fashioned Perl regular expressions. It stores the data in a simple hash structure, and "aliases" certain tags so that when done, you can count on having the minimal data necessary for re-constructing a valid RSS file. This means you get the basic title, description, and link for a channel and its items.

This module extracts more usable links by parsing "scriptingNews" and "weblog" formats in addition to RDF & RSS. It also "sanitizes" the output for best results. The munging includes:

Remove html tags to leave plain text
Remove leading whitespace from URIs
By defaul strips characters except 0-9~!@#$%^&*()-+=a-zA-Z[];',.:"<>?\s
Use <url> tags when <link> is empty
Use misplaced urls in <title> when <link> is empty
Exract links from <a href=...> if required
Limit links to ftp and http(s)
Join relative item urls (beginning with / or #) to the site base

Export

parseRSS($outHashRef, $inScalarRef, [$strip])
inScalarRef - required

Reference to a scalar containing the document to be parsed. NOTE: The contents will effectively be destroyed. Make a deep copy first if you care.

outHashRef - required

Reference to the hash within which to store the parsed content.

strip - optional

An expression indicating the level of winnowing to be performed on the characters permitted in the results.

1 strip non-printable characters
0 no characters are removed
undefined (Default) strip everything but:

0-9~!@#$%^&*()-+= a-zA-Z[];',.:"<>?\t\n

Exportable

parseXML(\%parsedTree, \$parseThis, 'topTag', $comments);
parsedTree - required

Reference to hash to store the parsed document within.

parseThis - required

Reference to scalar containing the document to parse.

topTag - optional

Tag to consider the root node, leaving this undefined is not recommended.

comments - optional
false will remove contents from parseThis
true will not remove comments from parseThis
array reference is true, comments are stored here

Caveats

This is not a conforming parser. It does not handle the following

•
  <foo bar=">">
•
  <foo><bar> <bar></bar> <bar></bar> </bar></foo>
•
  <![CDATA[ ]]>
•
  PI

It's non-validating, without a DTD the following cannot be properly addressed

entities
namespaces

This may or may not be arriving in some future release.

Pod errors

Hey! The above document had some coding errors, which are explained below:

Around line 480:

=back without =over

Releases

10 releases since Debian 4.0 (Etch); the text changed 6 times.

  1. 4.0
  2. 5.0
  3. 7–9
  4. 10
  5. 11
  6. 12–13
  7. Arch

Author

Jerrad Pierce <[email protected]>.

Scott Thomason <[email protected]>

License

Portions Copyright (c) 2002,2003,2009 Jerrad Pierce, (c) 2000 Scott Thomason. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

From perl-xml-rsslite 0.17-2 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.