XML API Feature

Hello, I’d like to make the request for an XML API to support easy loading and parsing of XML. I’m looking to use this with Corona Game Edition because I’ll be writing a game editor tool that will write out XML data that must then be read into the game. The current solutions seem overly time consuming or complex and having an easy to use API in Corona would be a great help.

Here are some other threads asking for essentially the same thing:

http://developer.anscamobile.com/forum/2010/04/06/e4x-style-xml-parsing

http://developer.anscamobile.com/forum/2010/04/28/xml-json-ini-parser-support

Whatever API is provided I’d like to see something similar to E4X that makes it easy to load game data and make changes to the code even as the XML schema changes through the development of the game editor and the game.
[import]uid: 8692 topic_id: 2012 reply_id: 302012[/import]

Couldn’t agree more. A basic xml api is a necessity in a game engine. [import]uid: 8545 topic_id: 2012 reply_id: 5899[/import]

Although not quite an API we use http://lua-users.org/wiki/LuaXml

We are looking at implementing a Corona XML framework.

Carlos [import]uid: 24 topic_id: 2012 reply_id: 6080[/import]

Thanks I’ll give this a try for now although I can see us outgrowing this rather quickly. A Corona XML framework as you mention is going to be needed for larger projects. Maybe you can adapt some of the code from LuaXML:
http://www.viremo.de/LuaXML/

They are using the MIT license so that might worth looking at.
[import]uid: 8692 topic_id: 2012 reply_id: 6144[/import]

AFonseca

We are looking at bigger picture. As a matter of fact, as a side note, one of our Board Advisors who used to work with me at Adobe, wrote his own XML parser for his Corona project and once he finishes his app, he will end up giving us his XML parser. I havent’ seen the code, so I can’t comment as to what it can and can’t do, but knowing him…

We will look at the LuaXML you mention.

Thanks

Carlos [import]uid: 24 topic_id: 2012 reply_id: 6194[/import]

Thanks for keeping us up to date, that sounds great. Hopefully he’ll be done soon so we don’t have to invest too much time/effort in using external libraries. [import]uid: 8692 topic_id: 2012 reply_id: 6345[/import]

I’ll check out the link provided above, but I’d like to second the request for builtin XML support.

[import]uid: 9562 topic_id: 2012 reply_id: 11241[/import]

hi any news on this, is it implemented or still planned? [import]uid: 13099 topic_id: 2012 reply_id: 14902[/import]

I’ll be writing a game editor tool that will write out XML data that must then be read into the game.

I do this very thing using Maya for level editing (ie. I wrote a Python script that dumps out an XML file of all the objects in the scene.) That’s for 3D but I’ll probably do the same thing to place things in 2D. [import]uid: 12108 topic_id: 2012 reply_id: 14908[/import]

Any news on the API? I really would like to see an E4X-Like approach in Corona. We’re developing apps and looking for a multiscreening approach (which adobe failed up to now with its approach in flash) but need heavy XML-support.

I have yet to try the LuaXML script though… but it seems a bit complicated and limited to me.
[import]uid: 12870 topic_id: 2012 reply_id: 16113[/import]

Just thought I would quickly chime in as well as I’m looking to do a few apps, game and non-game that would use XML rather heavily and having something like http://viremo.eludi.net/LuaXML/ in an API would be a god send for what I’m looking to do. So count this as a +1 for a robust XML API. [import]uid: 13813 topic_id: 2012 reply_id: 16426[/import]

Hi,

We have been looking at LuaXML and it seems there are now more questions than answers concerning lua XML parsing. A Corona XML framework would be a very welcome and essential feature. So count this as +1 as well.

Additionally a Corona web service (SOAP) framework would be a brilliant feature. Our games use web services extensively and we are struggling to implement a reliable and easy-to-use solution in Corona as yet.

Many thanks for all your work. [import]uid: 18203 topic_id: 2012 reply_id: 19923[/import]

this looks interesting
http://www.birtles.org.uk/xmltv/wiki/index.php/Xml_to_table

resulting in code like
[lua]aentre.dvddata = XmlToTable:ParseFile(file)

for i, dvd in ipairs(aentre.dvddata.Children.Collection[1].Children.DVD) do[/lua]

[text]


1256925082
12569-25082
2006-02-05 23:42:25
Absolute Power
Absolute Power

1



Main Feature (A: P&S; B: W/S)
6380AEBAE47E8071
4D1303A1F61CF735
True
False
He was where he shouldn’t have been and saw what he shouldn’t have seen. Now, who will believe the word of a career thief and ex-con? Who will trust Luther Whitney when he says he saw a woman killed - and that the man responsible for her death is the President of the United States? Clint Eastwood portrays Whitney and directs this crisp, finely acted thriller based on David Baldacci’s best-selling novel. A stellar cast which includes Gene Hackman and Ed Harris creates well-rounded characters that intensify a constantly spiralling game of cat and mouse between Whitney, local police and the highest levels of White House power. Eastwood is a master at steadily raising the stakes in thrillers. Here his mastery is absolute.
2006-04-29


[/text] [import]uid: 6645 topic_id: 2012 reply_id: 19927[/import]

check out this example
http://developer.anscamobile.com/forum/2011/01/04/can-someone-offer-some-insight-how-access-weather-report#comment-19670 [import]uid: 12108 topic_id: 2012 reply_id: 19937[/import]

+1 on implemented xml support in Corona!

This example takes me forward: http://developer.anscamobile.com/code/weather-app-example but I’m still new at this so i make it in ant-steps.

Easer to create a physics game than to read a xml file and do the right things with the information. :slight_smile: [import]uid: 28895 topic_id: 2012 reply_id: 20338[/import]

Hi,

As I have struggled with XML parsing in Lua, I thought I would share the functions I am now using. It is by far not a great solution but at least everything is written in Lua (no libraries). I believe this code was originally posted (and maybe even written) by Carlos. As I struggled to find it I thought I post it here:

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 parseXML(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.w3schools.com/ajax/note.xml") -- blah blah use your own url  
  
x = parseXML(b); -- parse xml  
  
-- Do whatever you want with the data...  
print("To:", x[2][1][1])  
print("From:", x[2][2][1])  
print("Message:", x[2][4][1])  

I hope this helps.

Cheers!
[import]uid: 18203 topic_id: 2012 reply_id: 20342[/import]

Thanks to whomever wrote what nanonil posted. I modified it for an associative table structure. It’s not comprehensive, but seems ok for simple XML parsing.

[code]
–usage
local xmlParser = require “xml”
xml = xmlParser.parseXML( “MyTitle
item1item2” )
print( xml.stuff.items.item[1].value )
print( xml.stuff.items.item[1].guid )

–the module
module(…, package.seeall)

local function loadAttributes( element, s )
string.gsub( s, “(%w+)=([”’])(.-)%2", function ( w, _, a )
element[w] = a
end )
end

function parseXML( 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
top.value = text
end

if empty == “/” then – empty element tag
loadAttributes( top, xarg )

elseif c == “” then – start tag
top = {}
loadAttributes( top, xarg )
table.insert( stack, top )

else – end tag
local close = table.remove( stack )
top = stack[#stack]

if top[label] then
if #top[label] ~= 0 then
table.insert( top[label], close )
else
local node = top[label]
local collection = {}
table.insert( collection, node )
table.insert( collection, close )
top[label] = collection
end
else
top[label] = close
end
end
i = j+1
end
return stack[1]
end
[/code] [import]uid: 4596 topic_id: 2012 reply_id: 25581[/import]

[import]uid: 31718 topic_id: 2012 reply_id: 27629[/import]

with regard to singh206 update

if you need to get the number of items

print( table.getn(xml.stuff.items.item) )

[import]uid: 67614 topic_id: 2012 reply_id: 39999[/import]

Any word on an official XML parser as part of the Corona SDK? We’re creeping up on a year since my original post. :slight_smile: [import]uid: 8692 topic_id: 2012 reply_id: 40000[/import]