Possible to pull an rss feed and display

I want to create few niche ‘news’ type apps that pull feeds from various sources, nothing to extensive just a basic rss reader. Is it possible at this point.

I’m thinking something like the rotowire app that basically just displays the latest news and you can scroll through headlines and open up safari upon tap and read web article.

Any thoughts? [import]uid: 3715 topic_id: 472 reply_id: 300472[/import]

I’d like to do the same. Does Corona have any xml parsing methods? [import]uid: 4637 topic_id: 472 reply_id: 1067[/import]

I’m struggling with xml at the moment. Carlos posted one in the thread “Load XML from http and parse it” which works fine as far as it goes, but it doesn’t populate the resulting table in a very useable way. I’d like/expect a table to use the xml data label tags as the table key and the values as the table values, but it’s not so.

I’ve also been pointed at xpath, but for the life of me cannot get the damn thing installed (it bitches about module.utils not being present).

Any ideas? [import]uid: 4523 topic_id: 472 reply_id: 1310[/import]

I posted xlm code in this forum

http://developer.anscamobile.com/forum/2010/01/11/load-xml-http-and-parse-it

does that work? [import]uid: 24 topic_id: 472 reply_id: 1315[/import]

I got that Carlos, and it works great, but doesn’t create something I can really use (or at least not the way I’d like to)

How would I access a particular element of the xml (table)?

I’d like to use something like this …

print myTable.Product.ProductTitle

Where myTable is the table generated from the xml and Product & ProductTitle are elements of the table (Product would be a table itself).

Cheers

Gary [import]uid: 4523 topic_id: 472 reply_id: 1322[/import]

Take a look here: http://lua-users.org/wiki/LuaXml; there is at least one usable pure lua xml parser that has more features that what Carlos whipped up. Worth taking a look at, anyway.

Medium term, Ansca could include lua expat and the expat lib in the SDK because we don’t yet have access to C extensions on our own. I think that would be the easiest thing to get working. [import]uid: 5597 topic_id: 472 reply_id: 1396[/import]

Team

we have a feature slated for better XML integration and we are working on doing it at the C level and have Lua API that should be a lot easier and more robust than the current set found at the lua site.

I have used the lua xml parser and it has worked for me and some of the other ansca team member.

But thanks to the feedback such as yours, we are going to improve our XML feature for the upcoming release.

Carlos [import]uid: 24 topic_id: 472 reply_id: 1399[/import]

+1 on XML improvement. Although I havent really used XML extensively in Corona, but personally, I’d like to see an E4X like implementation.

element.anotherElement
element.anotherElement.@attribute

Jon [import]uid: 3544 topic_id: 472 reply_id: 1405[/import]

E4X would be good.

I used Carlos’ code to read and display RSS in the app I’m making. I just accessed it like parsed_xml[1][1][i][1][1] for example, I just used the printTable function to work out the structure of the table then just access it like that, not ideal, but it works. [import]uid: 5708 topic_id: 472 reply_id: 1407[/import]

Hi guys,
I’m trying to understand corona, (I’m a flasher).
I need to parse an xml and I sow the code posted by Carlos.
I did a copy and paste in a main.lua file and open the project with the corona simulator, but nothing happen.
the screen remain black…I did something wrong?
ast [import]uid: 5762 topic_id: 472 reply_id: 1462[/import]

Open with the corona terminal you are probably getting error messages in there. [import]uid: 5708 topic_id: 472 reply_id: 1467[/import]

thank you smartmike,

I did not get any error message, the code is working and simply printing only in the terminal, nothing on the iphone screen.
ast
[import]uid: 5762 topic_id: 472 reply_id: 1485[/import]

Yeah, the printTable method is showing you how the xml data has been entered into a table, you then access the data in that table and display it how you like. [import]uid: 5708 topic_id: 472 reply_id: 1491[/import]

Yes I was wondering…
and I discover that the table is like an array, but the way to access data it’s seems really different than the array… [import]uid: 5762 topic_id: 472 reply_id: 1493[/import]

It’s pretty similar to how you access array data. just note the nodes you need (indicated by the numbers in the printTable function and access it like xmldata[1][2][1][1] or whatever the node is you need. [import]uid: 5708 topic_id: 472 reply_id: 1494[/import]

for exapmple if i got an XML like this:
<xmlData>
<item>
<field1>field1 value</field1>
<field2>field2 value</field2>
<field3>field3 value</field3>
</item>
</xmlData>
after the parsing, I can access the value of the field2 whith something like this?

field2Value = xmlData[1][1][2] [import]uid: 5762 topic_id: 472 reply_id: 1511[/import]

The output from print table would give you

[1] = table: 0x18d1fb60
{
[1] = table: 0x248660
{
[1] = table: 0x256da0
{
[1] = field1 value
[xarg] = table: 0x2eead0
{
}
[label] = field1
}
[2] = table: 0x276410
{
[1] = field2 value
[xarg] = table: 0x2820d0
{
}
[label] = field2
}
[3] = table: 0x18d0b3e0
{
[1] = field3 value
[xarg] = table: 0x274d70
{
}
[label] = field3
}
[xarg] = table: 0x26bcc0
{
}
[label] = item
}
[xarg] = table: 0x2d9740
{
}
[label] = xmlData
}
xml_data[1].length would give you the amount of items, then you could access each one like
xml_data[1][i][1][1] = field data 1
xml_data[1][i][2][1] = field data 2
xml_data[1][i][3][1] = field data 3

I think that’s right anyway, where i above is the item you want (in your example there is only 1 so 1 will do) [import]uid: 5708 topic_id: 472 reply_id: 1512[/import]

Thank you smartmike
but I think that should be something wrong…
this is the carlos funtion to parse the XML where I add the xml formatted as above

local http = require(“socket.http”)
local io = require(“io”);
local ltn12 = require(“ltn12”)

function parseargs(s)
local arg = {}
string.gsub(s, “(%w+)=([”’])(.-)%2", function (w, _, a)
arg[w] = a
end)
return arg
end

function collect(s)

local stack = {}
local top = {}
table.insert(stack, top)
local ni,c,label,xarg, empty
local i, j = 1, 1
while true do
ni,j,c,label,xarg, empty = string.find(s, “”, i)
if not ni then break end
local text = string.sub(s, i, ni-1)
if not string.find(text, “^%s*$”) then
table.insert(top, text)
end
if empty == “/” then – empty element tag
table.insert(top, {label=label, xarg=parseargs(xarg), empty=1})
elseif c == “” then – start tag
top = {label=label, xarg=parseargs(xarg)}
table.insert(stack, top) – new level
else – end tag
local toclose = table.remove(stack) – remove top
top = stack[#stack]
if #stack < 1 then
error("nothing to close with "…label)
end
if toclose.label ~= label then
error("trying to close “…toclose.label…” with "…label)
end
table.insert(top, toclose)
end
i = j+1
end
local text = string.sub(s, i)
if not string.find(text, “^%s*$”) then
table.insert(stack[#stack], text)
end
if #stack > 1 then
error("unclosed "…stack[stack.n].label)
end
return stack[1]
end

b = http.request( “http://www.digitalpromo.it/webradio/listaBrani.xml”) – blah blah use your own url

x = collect(b); – parse xml

print (x);

– then the function to print the length value

local function printXML(xml)
if xml then

print(xml[1].length)

end
end

printXML(x);

if you try to execute you’ll retreive a nil value

ast
[import]uid: 5762 topic_id: 472 reply_id: 1574[/import]