How to parse XML documents?

LuaExpat is the best known of the Lua XML bindings. This implements a SAX API where one registers callbacks to handle each element parsed.

The lxp.lom module brings an XML document into memory as a LOM table (Lua Object Model):

Given this XML fragment:

<abc a1="A1" a2="A2">inside tag `abc'</abc>

lxp.lom.parse will give you the following table structure:

{
 [1] = "inside tag `abc'",
 ["attr"] = {
 [1] = "a1",
 [2] = "a2",
 ["a1"] = "A1",
 ["a2"] = "A2",
 },
 ["tag"] = "abc",
}

The rules of LOM are simple:



Back