Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
juergen committed Aug 12, 2007
1 parent 85dd026 commit 289ea53
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions examples/rss.lua
@@ -1,5 +1,6 @@
-- use LuaExpat and Lua-CuRL together for On-The-Fly XML parsing
require("lxp")
require("cURL")

callback = {}
tags = {}
Expand All @@ -14,8 +15,8 @@ end

function callback.CharacterData(parser, str)
if (tags[#tags -1] == "item") then
--we are parsing a item
items[#items][tags[#tags]] = str
--we are parsing a item, get rid of trailing whitespace
items[#items][tags[#tags]] = string.gsub(str, "%s*$", "")
end
end
function callback.EndElement(parser, tagname)
Expand All @@ -25,12 +26,18 @@ end

p = lxp.new(callback)

f = io.open("slashdot", "r")
-- create and setup easy handle
c = cURL.easy_init()
c:setopt_url("http://www.lua.org/news.rss")

for l in f:lines() do
assert(p:parse(l))
-- assert(p:parse("\n"))

m = cURL.multi_init()
m:add_handle(c)

for data,type in m:perform() do
-- ign "header"
if (type == "data") then
assert(p:parse(data))
end
end

assert(p:parse()) --finish document
Expand Down

0 comments on commit 289ea53

Please sign in to comment.