PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: NotRabidWombat on 19 July, 2004, 12:47:34

Title: Simple XML Parser
Post by: NotRabidWombat on 19 July, 2004, 12:47:34
function XMLtoTable(sString)
if( not sString ) then return ""; end

local s, e, sTag, sTemp = strfind(sString, "^<([^>]-)>(.*)$");
local sInner;

-- we have a tag
if(s) then
sString = sTemp;
local tTable = {};

while sTag do
s, e, sTag = strfind(sTag, "^(%S+)");

s, e, sInner, sString = strfind(sString, "^(.-)(.*)$");

if( not tTable[sTag] ) then
tTable[sTag] = {};
end

tinsert(tTable[sTag], XMLtoTable(sInner));

s, e, sTag, sString = strfind(sString, "<([^>]-)>(.*)$");
end

return tTable;

-- we have data
else
return sString;
end
end
Very simple parser right now. I intend to make it better.

Used it to export YHub accounts to another hub soft. Probably has a million other uses.

-NotRabidWombat
Title:
Post by: Herodes on 19 July, 2004, 13:38:07
make that billion of uses ... thanks for keeping it fresh NotRambitWombat ..
Cant wait to see what else u can do :)
Title: Uses for an XML parser
Post by: FlatLynr on 05 October, 2004, 10:06:42
I originally used Excel to convert my yhub accounts to Ptokax and I really wish I'd has this script then, it's much more elegant and would have saved me having to work with a 20MB spreadsheet  8o

Since I missed out on my chance to use it there, I'm going to make a (possibly foolhardy) attempt to use it to create a next gen nForce bot now that their scripts are XML. Probably just get it to generate a simple text file and use one of the timed message bots around to broadcast them although if I can get my head around the language enough (just learning), I'll try to make it into a full bot with commands etc.

I'll keep the board posted on any developments but if anyone's working on something similar, I'd love to hear how you're getting on.
Title:
Post by: bastya_elvtars on 08 October, 2004, 11:33:13
hehe rabidwombat put another nail in yhub's coffin - very nice! heh heh sorry for this offtopic post but i really hate yhub! :evil:
Title:
Post by: dkt on 03 June, 2005, 03:08:29
wats the use of this script in brief ???

and how to use it ?