I am trying to parse data from XML files, for example
<level> <bg>details1</bg> <bg>details2</bg> </level>
With xml.find (bg) I can only get details 1. This is because xml.find returns the first (sub) table that matches the search condition or nil.
If I want to read both bg out. How can I achieve this in LuaXML? Or please check out other Lua XML libraries.
Addons My real scenario is like this
<a> <b> <level> <bg>details1</bg> </level> <level> <bg>details2</bg> </level> </b> </a>
I know that I need to get the whole object b and use xml.tag to read the level. But my attempts fail. Could you help me in this code?
I finally got my decision based on a proposal from Mike Corcoran.
require 'luaxml' local text = [[ <a> <bcde> <level> <bg>details1</bg> </level> <level> <bg>details2</bg> </level> </bcde> </a> ]] local txml = xml.eval(text) for _, node in pairs(txml:find("bcde")) do if node.TAG ~= nil then if node[node.TAG] == "level" then local bg = node:find("bg") if bg ~= nil then for i=1,
Too many layers and it seems slow .. Any suggestion to increase efficiency?
source share