I looked inside lib - it does strong encoding for all> 127 bytes, thereby breaking UTF into separate characters. It does this after using the built-in .registerCode mechanism, so you cannot even override it.
If you need to encode some complex data structure, you can simply expand all these object substitutions after the completion of XmlLua , declaring somewhere:
local high_ascii_unroll = {} for code = 128, 255 do high_ascii_unroll['&#' .. code .. ';'] = string.char(code) end
and then using gsub in the final line:
local doc = xml.new("outer") doc.version = "2.0" local inner = xml.new("inner") inner.id = "" table.insert(doc, inner) local encoded = xml.str(doc):gsub('&#%d+;', high_ascii_unroll) -- <outer version="2.0"> -- <inner id="" /> -- </outer>
source share