lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 28 November 2010 14:14, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> I'm looking for Lua module(s) to work with RSS.
>
> The code below parses http://www.lua.org/news.rss for instance.
> It may be a start.
>
> local function parse(name,t)
>        local leaf=true
>        for k,b in string.gmatch(t, "<(%w+).->(.-)</%1>") do
>                parse(name..k..".",b)
>                leaf=false
>        end
>        if leaf then print(name,t) end
> end
>
> parse("",io.read"*a")

I used to use this code in a bot. It worked fine with some (especially
large) feeds, with other feeds it would use lots of CPU and/or RAM (it
was some years back, I can't remember) so I had to disable it. It's
certainly fine if you have a fixed feed that you know works and don't
want to add any dependencies, though for general-purpose feed parsing
it's probably better to go with a real XML parser.

Regards,
Matthew