-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ec1391
commit 6960e74
Showing
3 changed files
with
70 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
local XmlParser = require('XmlParser') -- xml2lua parser | ||
|
||
local function errorHandler(errMsg, pos) | ||
error(string.format("%s [char=%d]\n", errMsg or "Parse Error", pos)) | ||
end | ||
|
||
local function starttag(handler, tag) | ||
handler:startElement(tag.name, tag.attrs) | ||
end | ||
|
||
local function endtag(handler, tag) | ||
handler:endElement(tag.name) | ||
end | ||
|
||
return { | ||
new = function(_, handler) | ||
handler.starttag = starttag | ||
handler.endtag = endtag | ||
return XmlParser.new(handler, { | ||
stripWS = true, -- Indicates if whitespaces should be striped or not | ||
expandEntities = false, | ||
errorHandler = errorHandler | ||
}) | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
local lxpLib = require('lxp') | ||
|
||
local function startElement(p, name, attrs) | ||
local handler = p:getcallbacks().handler | ||
handler:startElement(name, attrs) | ||
end | ||
|
||
local function endElement(p, name) | ||
local handler = p:getcallbacks().handler | ||
handler:endElement(name) | ||
end | ||
|
||
local function cdata(p, text) | ||
local handler = p:getcallbacks().handler | ||
handler:cdata(text) | ||
end | ||
|
||
return { | ||
new = function(_, handler) | ||
-- see https://lunarmodules.github.io/luaexpat/manual.html | ||
-- lxp.new(callbacks [, separator[, merge_character_data]]) | ||
return lxpLib.new({ | ||
StartElement = startElement, | ||
EndElement = endElement, | ||
CharacterData = cdata, | ||
_nonstrict = true, | ||
handler = handler | ||
}) | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters