Replies: 1 comment
-
As a followup, I got something working as follows (all within a local handler = require("xmlhandler.tree")
local counter = 0
local myhandler = handler:new()
local org_text = myhandler.text
myhandler.text = function(handler, text)
if (counter % 50) == 0 then
coroutine.yield()
end
counter = counter + 1
return org_text(handler, text)
end
local myparser = xml2lua.parser(myhandler)
myparser:parse(xml2lua.loadFile("<my-file-path>")) But this seems hackish to me. It would be nice if there were a specifically supported parser or handler routine that could be used for it instead. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. Thank you for
xml2lua
. It is pretty close to ideal for my use case.I am parsing a rather large xml file (2MB+) into tables in lua for later processing. This takes a few seconds and has to be done every time the script runs. For that reason, I would like to run it in a
coroutine
and yield back to the caller on a periodic basis. This might be after every top-level tag or configurable to be after every tag of a specified name.I thought I saw a reference to callback functions in the docs, but now I'm not finding it. Is there a callback mechanism already built into the parser? If not, would it be hard to add? (I don't mind taking a stab at it myself if you want to point me in the right direction.)
Thanks
Beta Was this translation helpful? Give feedback.
All reactions