diff options
author | ubq323 <ubq323@ubq323.website> | 2024-08-26 16:11:02 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-08-26 16:11:02 +0100 |
commit | 643e4202f4c5a5ee7a87779ffb69928e685db451 (patch) | |
tree | ce2402d08e0ec32f2c7f4d9d8a6ea691859944f9 /xml.lua | |
parent | 82a68e3d97f88454ed0ca1b639aa61c0f59e352f (diff) |
ooo
Diffstat (limited to 'xml.lua')
-rw-r--r-- | xml.lua | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -1,3 +1,6 @@ +-- originally from http://lua-users.org/wiki/LuaXml +-- modified by me a bit + local function parseargs(s) local arg = {} string.gsub(s, "([%-%w]+)=([\"'])(.-)%2", function (w, _, a) @@ -6,6 +9,18 @@ local function parseargs(s) return arg end +local function tag(x) + return setmetatable(x, {__call=function(x, label) + -- search for child with given label + for _,c in ipairs(x) do + if c.label == label then + return c + end + end + return nil + end}) +end + local psingle local function pmulti(s, i, parent) @@ -41,11 +56,11 @@ psingle = function(s, i) end if empty == "/" then - return nexti, {label=label, xarg=parseargs(xarg), empty=true} + return nexti, tag{label=label, xarg=parseargs(xarg), empty=true} elseif c == "" then -- start tag - return multi(s, nexti, {label=label, xarg=parseargs(xarg)}) + return pmulti(s, nexti, tag{label=label, xarg=parseargs(xarg)}) else -- end tag - return nexti, {label=label, close=true} + return nexti, tag{label=label, close=true} end end @@ -63,7 +78,8 @@ local function stanzae(getmore) coroutine.yield(el) buf = buf:sub(ni) else - buf = buf..getmore() + local more = getmore() + buf = buf .. more end end end) |