mod XML lua
Posted: Mon Nov 10, 2008 6:07 am
Hey Elverion,
I've been using the mod XML Parser as u know, I ran into a parser error, which had me stumped for a bit, so I decided to add error handling for the parse() call in the open function, here it is:
If you could add this to the XML file that would be cool. 
I've been using the mod XML Parser as u know, I ran into a parser error, which had me stumped for a bit, so I decided to add error handling for the parse() call in the open function, here it is:
Code: Select all
function open(filename)
callbacks = {
StartElement = startElement,
EndElement = endElement,
CharacterData = characterData,
_nonstrict = true,
stack = {{}}}
local p = lxp.new(callbacks);
local file = io.open(filename);
if( file == nil ) then
local err = string.format("Cannot open file \'%s\' for reading.", filename);
error(err, 0);
end
local parse = {}
for l in file:lines() do
parse.result, parse.msg, parse.line, parse.col, parse.pos = p:parse(l)
if (parse.result) then
else
error("XML Parse Error." ..
"\nfile: " .. filename ..
"\nline: " .. parse.line ..
"\ncolumn: " .. parse.col ..
"\nabsolute postion: " .. parse.pos ..
"\nmessage: " .. parse.msg)
end
p:parse("\n");
end
p:parse();
p:close();
file:close();
return callbacks.stack[1][1];
end