\startluacode -- Define our namespace as hvdm hvdm = hvdm or {} -- Function checks the correctness of an XML tree. hvdm.checkXMLtree = function (xml, linesep) local xml = xml and xml or "" local linesep = linesep and linesep or "\n" local badspace = {} -- Empty files do not need processing. if xml == "" then return "" end -- Step one is remove leading characters before first node. local leadingnode = string.find(xml, "<", 1) or 1 if leadingnode ~= 1 then xml = string.sub(xml, leadingnode, -1) end -- Strip all comments but node pairs inside make it complicated. local c1, c2 = string.find(xml, "", c2 + 1, true) if c3 then -- Remove comment. xml = string.sub(xml, 1, c1 - 1) .. string.sub(xml, c4 + 1, -1) -- Search for next comment. c1, c2 = string.find(xml, "