Skip to content

Latest commit

 

History

History
81 lines (56 loc) · 3.29 KB

README.md

File metadata and controls

81 lines (56 loc) · 3.29 KB

expadom

Build Luacheck Coveralls code coverage SemVer License

An XML DOM Level 2 Core implementation in Lua, based on the (Lua)Expat parser.

Status

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.

Synopsis

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"

Documentation

The documentation and reference is available in the /docs folder, and online.

Downloads, dependencies, and source code

Source code and downloads are available from the Github project page. Installation is typically easiest using LuaRocks.

Dependencies

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.

License & Copyright

The project is licensed under the MIT License

History

unreleased

  • Feat: return root element as well when creating a document (DOMimplementation) #5

22-Apr-2022 0.1.0 Initial release

  • Most of the DOM level 2 has been implemented