lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

PA wrote:
> Alternatively, somebody, somewhere, somehow must have written this a
> dozen time already. Is there not a little code sample somewhere to show
> how to decode an XML string in Lua? Sigh...

nontested:

reptable = {
	lt = "<",
	gt = ">",
	apos = "'",
	quot = '"',
	amp = "&",
}

outstring = string.gsub (instring, "&([^;]*);", function (s)
	local rep = reptable[s]
	if rep then return rep end

	if sub (s, 1,1) == "#" then
		local n = tonumber ( string.sub( s, 2 ) )
		if ( ( n ~= nil ) and ( n > 0 ) and ( n < 255 ) ) then
			return string.char( n )
		end
	end
end
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCPsgtsIoGnxsRK/ERAqezAKCc9QcAISH780dk0BOHkuLVKKqybACgkdBi
3RrO8soOT5Iq9kPpu7uNeuU=
=adAj
-----END PGP SIGNATURE-----