An XML DOM Level 2 Core implementation in Lua, based on the (Lua)Expat parser.
This library is under early development and does not have everything implemented
yet. Scan the code for "TODO:"
to see what is still to be done.
local DOM = require("expadom.DOMImplementation")()
local doc, root = DOM:createDocument(nil, "root")
root:appendChild(doc:createComment("let's create an address list"))
local list = doc:createElement("addresses")
list:setAttribute("country", "Netherlands")
root:appendChild(list)
local addr = doc:createElement("address")
list:appendChild(addr)
addr:appendChild(doc:createTextNode("address goes here"))
local xml_written = table.concat(doc:write())
-- result (formatting added for readability):
-- <?xml version="1.0" encoding="UTF-8"?>
-- <root>
-- <!--let's create an address list-->
-- <addresses country="Netherlands">
-- <address>address goes here</address>
-- </addresses>
-- </root>
-- now parse the document again:
local xml_parsed = require("expadom").parseDocument(xml_written)
local address = xml_parsed:getElementsByTagName("address")[1]
print(address.childNodes[1].nodeValue) --> "address goes here"
The documentation and reference is available in the /docs
folder, and online.
Source code and downloads are available from the Github project page. Installation is typically easiest using LuaRocks.
Expadom depends on the following packages:
- LuaExpat for parsing XML. This requires that libexpat itself is also installed.
- The Lua module compat53 is required
for UTF-8 support on Lua versions lacking the
utf8
module (pre Lua 5.3).
When installing through LuaRocks, libexpat
must be installed manually, the other
dependencies will be dealt with by LuaRocks.
The project is licensed under the MIT License
- Feat: return root element as well when creating a document (DOMimplementation) #5
- Most of the DOM level 2 has been implemented