Hi guys,
I’m having a terrible time trying to parse an rss feed from the web. I’ve tried all sorts of xml parsers off of the lua website, and the coronaui one as well (though that one at least gave me errors). I’m trying to convert this stuff to a table. Also, this rss feed is not something I can readily adjust from the other end. I have to take whatever is being sent to me and configure it from corona.
I’m using some code I got off of the forum or code exchange in conjunction with the coronaui parser.
here’s what I have so far:
[lua]-- load needed modules
local http = require(“socket.http”)
local ltn12 = require(“ltn12”)
– a simplified http.get function
local function httpget(u)
local t = {}
local r = http.request{
url = u,
sink = ltn12.sink.table(t)
}
return t
end
local function dump(o)
if type(o) == ‘table’ then
local s = ‘{ ’
for k,v in pairs(o) do
if type(k) ~= ‘number’ then k = ‘"’…k…’"’ end
s = s … ‘[’…k…’] = ’ … dump(v) … ‘,’
end
return s … '} ’
else
return tostring(o)
end
end
local x = httpget(“http://hm.bhusd.org/apps/events/events_rss.jsp?id=1”)
local xmlParser = coronaui.newXmlParser()
local temp2 = xmlParser:ParseXmlText(dump(x))[/lua]
if I use xmlParser:FromXmlString(dump(x)), then it runs, but I just end up with one long string instead of a table.
and then I get this message in the terminal:
XmlParser: trying to close br with description
XmlParser: trying to close br with item
XmlParser: trying to close br with description
XmlParser: trying to close br with item
XmlParser: trying to close br with description
XmlParser: trying to close br with item
XmlParser: trying to close br with description
XmlParser: trying to close br with item
XmlParser: trying to close br with description
XmlParser: trying to close br with item
XmlParser: trying to close description with channel
XmlParser: trying to close item with rss
Runtime error
…Svm99p2jsk+++TI/-Tmp-/TemporaryItems/41/coronaui.lua:137: attempt to index field ‘?’ (a nil value)
stack traceback:
[C]: ?
…Svm99p2jsk+++TI/-Tmp-/TemporaryItems/41/coronaui.lua:137: in function ‘ParseXmlText’
[import]uid: 10211 topic_id: 9096 reply_id: 35023[/import]