feeder - parse RSS and Atom
The feeder Erlang library parses RSS and Atom formatted XML feeds. It is a stream based parser that sends its events through a callback interface.
Usage
Parse a file and accumulate parser events:
-module(acc).
-export([file/1]).
event({entry, Entry}, {Feed, Entries}) ->
{Feed, [Entry|Entries]};
event({feed, Feed}, {[], Entries}) ->
{Feed, Entries};
event(endFeed, {Feed, Entries}) ->
{Feed, lists:reverse(Entries)}.
opts() ->
[{event_state, {[],[]}}, {event_fun, fun event/2}].
file(Filename) ->
{ok, EventState, _Rest} = feeder:file(Filename, opts()),
EventState.Example
To try HTTP streaming do:
cd example
make
erl -pa ebin deps/*/ebin
example:start().
example:print_titles("http://5by5.tv/rss").Types
feed()
The channel or feed tuple.
enclosure()
The enclosure tuple for an item or entry.
entry()
An item or entry tuple.
option()
Options to setup the parser.
{continuation_fun, ContinuationFun}
ContinuationFun is a call back function to decide what to do if the parser runs into EOF before the document is complete.
{continuation_state, term()}
State that is accessible in the continuation call back function.
{event_fun, EventFun}
EventFun is the call back function for parser events.
{event_state, term()}
State that is accessible in the event call back function.
event()
The events that are sent to the user via the callback.
{feed, Feed}Feed = feed()
Receive notification when the meta information of the feed or channel has been parsed.
{entry, Entry}Entry = entry()
Receive notification for each entry or article in the feed.
endFeedReceive notification of the end of a document. feeder will send this event only once, and it will be the last event during the parse.
Exports
Parsing feeds
feeder:file(Filename, Opts) -> ResultFilename = string()Opts = [option()]Result = {ok, EventState, Rest}Rest = unicode_binary() | latin1_binary()EventState = term()
feeder:stream(Xml, Opts) -> ResultXml = unicode_binary() | latin1_binary() | [unicode_char()]Opts = [option()]Result = {ok, EventState, Rest}Rest = unicode_binary() | latin1_binary()EventState = term()
Accessing values
feeder_feeds:get(Key, Feed) -> ValueKey = author | id | image | language | link | subtitle | summary | title | updatedFeed = feed()Value = binary() | undefined
feeder_enclosures:get(Key, Enclosure) -> ValueKey = url | length | typeEnclosure = enclosure()Value = binary() | undefined
feeder_entries:get(Key, Entry) -> ValueKey = author | duration | enclosure | id | image | link | subtitle | summary | title | updatedEntry = entry()Value = binary() | enclosure() | undefined