LXL is a non-validating XML 1.0 processor for Lua 5.1 - 5.4.

The docs can be read offline by downloading the repo and pointing your web browser to the files in docs/html5.

Features

  • Checks XML 1.0 well-formedness (syntax errors)

  • UTF-8, UTF-16 encoding

  • Namespace 1.0, 1.1 mapping

Not Supported

  • Does not validate XML documents (that is, check them against a DTD)

  • Does not support ignoring syntax errors (like HTML)

  • All PEReferences in the DTD Internal Subset are skipped; non-validating processors are not required to handle them.

  • Does not directly serialize DOCTYPE

  • No XML 1.1 features

Example

example1.lua
local lxl = require("path.to.lxl")

local xml_obj = lxl.toTable([=[
<foobar>
 <elem1 a1="Hello" a2="World">Some text.</elem1>
 <empty/>
</foobar>
]=]
)

xml_obj:pruneNodes("comment", "pi")
xml_obj:mergeCharacterData()
xml_obj:pruneSpace()

local root = xml_obj:getRootElement()

local e1 = root:find("element", "elem1")

if e1 then
	for k, v in pairs(e1.attr) do
		print(k, v)
	end
end
-- Output (the order may vary):
--[[
a1	Hello
a2	World
--]]


print(lxl.toString(xml_obj))
-- Output:
--[[
<?xml version="1.0" encoding="UTF-8"?>
<foobar>
 <elem1 a1="Hello" a2="World">Some text.</elem1>
 <empty/>
</foobar>
--]]

Files

These files are required:

lxl.lua
lxl_in.lua
lxl_namespace.lua
lxl_out.lua
lxl_shared.lua
lxl_struct.lua
p_assert.lua
p_interp.lua
p_name.lua
p_string_proc.lua
p_string_walk.lua
p_table.lua
p_tree.lua
p_utf8.lua
p_utf8_conv.lua

All files beginning with example or test may be removed.

License (MIT)

MIT License

Copyright (c) 2022 - 2026 RBTS / Frank F. Trafton

Code from github.com/kikito/utf8_validator.lua:
Copyright (c) 2013 Enrique GarcĂ­a Cota + Adam Baldwin + hanzao + Equi 4 Software

PILE Base:
  Copyright (c) 2024 - 2026 PILE Contributors

  LUIGI code: Copyright (c) 2015 airstruck
    https://github.com/airstruck/luigi

  lume code: Copyright (c) 2020 rxi
    https://github.com/rxi/lume

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

VERSION: 2.075