Lua Table to XML (and Back)

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Lua Table to XML (and Back)

Post by Arwin »

Hi Folks,

I am finally reading the Lua tutorials and noticed something. The Lua tables, how they can be nested, lend themselves perfectly to saving them as an xml file. When I imagine that I could save a lua table to xml, or read an xml file from the internet and access it as a nested lua table, I get all warm inside.

I'm not talking about the whole namespace, document template and so on, that would be more suitable for a full-fledged xml module. I would even ignore attributes. Perhaps only support CDATA sections (the <![CDATA[some text with annoying characters reserved for xml formatting]]> bit).

But the table structure and flexibility just really lends itself so well for it! It could be linked to database access and what not - I could just write an http request to an asp or php page, and get an xml string back that reads into a (nested) Lua table. I could save my tables holding my configuration and settings with one command to xml files on the memory stick.

All it would need is a save lua table command. Of course I could just write one in Lua, but this would serve such basic needs, I think nearly every single program could (and would) use it. Even those who don't care about xml will appreciate being able to save and load a(n optionally nested) table like that.

Or am I wrong?

(goes back to reading)
liquid8d
Posts: 66
Joined: Thu Jun 30, 2005 6:29 am

Post by liquid8d »

I am using tables write now to download ini-style files and read them right into a lua table... it works extremely well :) Its nice to just read in the key/value items for things, and they can be easily accessed.

[Name]
Desc=nifty stuff
Whatever=275

item[x].Name
item[x].Desc
item[x].Whatever

Certainly a nested table would be useful for xml. It's why I am suprised that we haven't had a working rss reader in lua yet... still waiting :P

liquid8d
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Hmm... What does pspRSS do then?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Lua Table to XML (and Back)

Post by Shine »

Arwin wrote:All it would need is a save lua table command. Of course I could just write one in Lua, but this would serve such basic needs, I think nearly every single program could (and would) use it. Even those who don't care about xml will appreciate being able to save and load a(n optionally nested) table like that.

Or am I wrong?
Why everyone wants XML? For Lua in my opinon it is much easier to save nested tables in Lua source format and just execute the file when loading it :-)
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Re: Lua Table to XML (and Back)

Post by Arwin »

Shine wrote:
Arwin wrote:All it would need is a save lua table command. Of course I could just write one in Lua, but this would serve such basic needs, I think nearly every single program could (and would) use it. Even those who don't care about xml will appreciate being able to save and load a(n optionally nested) table like that.

Or am I wrong?
Why everyone wants XML? For Lua in my opinon it is much easier to save nested tables in Lua source format and just execute the file when loading it :-)
Because XML is a widely used standard. Sure, using Lua source format works, but I have been using XML for this kind of thing in several languages for five years now, and others are picking it up also. I could just save some data from a database, and Lua could pick it up as a table and use it. Simple as that. And the other way around. Just one of many examples.

You may find it trivial, probably from not using XML for anything at the moment. But supporting XML like that would not be less trivial than supporting PNG files. They are both widely accepted standards, one for graphics, the other for data.
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

possibly this might help:
LUA to XML parser

greets
lumo
PS: might be another nice 'plugin' for luaplayer
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
modsyn
Posts: 28
Joined: Tue Sep 27, 2005 6:02 am

Post by modsyn »

i would love an XML/html to table function.
or at least the ability to drop in plugins. :)
Post Reply