![]() |
|
RSS Reader - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: RSS Reader (/showthread.php?tid=70) |
RSS Reader - Pawel - 28.08.2015 I want to show on visualization some rss feed. Is there some example of this functionality? Or maybe some library which help to work with xml files? RE: RSS Reader - admin - 31.08.2015 You can use LuaSocket to fetch the RSS feed and the parse it using LuaExpat: http://w3.impa.br/~diego/software/luasocket/http.html#request https://matthewwild.co.uk/projects/luaexpat/examples.html RE: RSS Reader - Pawel - 31.08.2015 Thanks, i didnt know which module, to handle with xml, you add. RE: RSS Reader - Pawel - 01.09.2015 Can you give me some working example of luaexpat? this, on the web you gave, is very strange and non documented, so understanding is very difficult. RE: RSS Reader - admin - 01.09.2015 Here's an example that will get text from <title> and <description> tags inside of each <item> tag and save them in a table. Code: itemtag = false
result = {}
-- callback for tag start
function starttag(parser, tag)
-- create new storage in result table for each <item> tag
if tag == 'item' then
itemtag = true
table.insert(result, {})
end
currtag = tag
end
-- callback for tag end
function endtag(p, tag)
if tag == 'item' then
itemtag = false
end
currtag = nil
end
-- callback for character data
function cdata(parser, text)
-- check if parser is inside of <item> and either in <title> or <description>
if itemtag and currtag then
if currtag == 'title' then
result[ #result ].title = text
elseif currtag == 'description' then
result[ #result ].description = text
end
end
end
-- create parser
lxp = require('lxp')
parser = lxp.new({
StartElement = starttag,
EndElement = endtag,
CharacterData = cdata,
})
-- sample data
data = [[
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.example.com/main.html</link>
<lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000 </lastBuildDate>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
<ttl>1800</ttl>
<item>
<title>Example entry</title>
<description>Here is some text containing an interesting description.</description>
<link>http://www.example.com/blog/post/1</link>
<guid isPermaLink="true">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
<item>
<title>Another example entry</title>
<description>Here is some other text containing an interesting description.</description>
<link>http://www.example.com/blog/post/1</link>
<guid isPermaLink="true">7bd204c6-1655-4c27-aeee-53f933c5395f</guid>
<pubDate>Sun, 06 Sep 2009 16:20:00 +0000</pubDate>
</item>
</channel>
</rss>
]]
if parser:parse(data) then
log(result)
else
log('parse failed')
endRE: RSS Reader - Pawel - 01.09.2015 The best and the fastest support in KNX world
|