PDA

View Full Version : xml safe data



Bidmaron
December 27th, 2010, 21:11
Does anyone have routines in lua that take strings and produce xml safe data (that is no & and <) from it (and vice versa)? Just too lazy to write them.

StuartW
December 27th, 2010, 21:30
I have some badly-written encode/decode routines:


function xmlEncode(value)
local result = string.gsub(value,"&","&amp;");
result = string.gsub(result,"<","&lt;");
result = string.gsub(result,">","&gt;");
return result;
end

function xmlDecode(value)
local result = string.gsub(value,"&gt;",">");
result = string.gsub(result,"&lt;","<");
result = string.gsub(result,"&amp;","&");
return result;
end

They're not very efficicent though...

Stuart

Bidmaron
December 31st, 2010, 12:25
Thanks, Stuart. I wrote something based on this.