Closed elihugarret closed 6 years ago
Thanks. I'm looking forward to your PR.
Yes please!! Lua 5.3 doesn't seem to have any other alternate XML parser for now :(
I'll take a look at it by the end of the week.
Hello @evnix and @elihugarret
I've fixed the issue. Now it works with Lua 5.1 to 5.3. I appreciate if you could give some feedback.
I found this,
lua -l set_paths x.lua lua: lua_modules/share/lua/5.3/xml2lua.lua:123: attempt to call a nil value (field 'new') stack traceback: lua_modules/share/lua/5.3/xml2lua.lua:123: in function 'xml2lua.parser' x.lua:8: in main chunk [C]: in ?
where x.lua is copied from example1.lua
Is x.lua an exact copy of example1.lua? Could you show the code here? What is your exact Lua version? I'm using 5.3.4.
testNet:examples silva$ lua -v
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
testNet:examples silva$ cat x.lua
local xml2lua = require("xml2lua")
--Uses a handler that converts the XML to a Lua table
local handler = require("xmlhandler.tree")
local xml = xml2lua.loadFile("people.xml")
--Instantiates the XML parser
local parser = xml2lua.parser(handler)
parser:parse(xml)
--Manually prints the table (since the XML structure for this example is previously known)
for k, p in pairs(handler.root.people.person) do
print("Name:", p.name, "City:", p.city, "Type:", p._attr.type)
end
testNet:examples silva$ cat people.xml
<?xml version="1.0" encoding="UTF-8"?>
<people>
<person type="P">
<![CDATA[
Just a CDATA tag that may contain anything, including XML code,
such as <tag>message</tag>.
Its content is extracted but not processed.
]]>
<!-- Just an example comment that will be ignored by the tree handler and processed by the other ones. -->
<name>Manoel</name>
<city>Palmas-TO</city>
</person>
<person type="P">
<name>Breno</name>
<city>Palmas-TO</city>
</person>
<person type="J">
<name>University of Brasília</name>
<city>Brasília-DF</city>
</person>
</people>
testNet:examples silva$ cat set_paths.lua
-- set_paths.lua
local version = _VERSION:match("%d+%.%d+")
package.path = 'lua_modules/share/lua/' .. version .. '/?.lua;lua_modules/share/lua/' .. version .. '/?/init.lua;' .. package.path
package.cpath = 'lua_modules/lib/lua/' .. version .. '/?.so;' .. package.cpath
testNet:examples silva$ lua -l set_paths x.lua
lua: lua_modules/share/lua/5.3/xml2lua.lua:123: attempt to call a nil value (field 'new')
stack traceback:
lua_modules/share/lua/5.3/xml2lua.lua:123: in function 'xml2lua.parser'
x.lua:8: in main chunk
[C]: in ?
The issue was when downloading using luarocks. I fixed the rock file. Use luarocks to download the new 1.1-1 version.
Yes it worked perfectly now. Thanks a lot :)
Hi! I noticed that this module does not work on Lua 5.3:
The "module" function is not supported on Lua 5.3. I want to help, I'll send you a pull request these days fixing this and making it compatible with the last version of Lua.