Closed fordcars closed 4 years ago
I couldn't reproduce the issue. That happened in a previous version. Try to uninstall:
luarocks remove xml2lua
and reinstall with
luarocks install xml2lua.
I'm using this table:
game {
resources {
object {
path = {"myFirstPath", "mySecondPath"}
}
}
}
And print(xml2lua.toXml(table))
produces the following XML:
<game>
<resources>
<object>
<path>myFirstPath</path>
<path>mySecondPath</path>
</object>
</resources>
</game>
Thanks for the quick reply! I am using v v1.4-2
directly from Github. Is there a later version from luarocks? I am still getting the incorrect output using your table.
To be clear, I am using print(xml2lua,toXml(table, "game"))
No, there isn't.
Try to update your clone/fork and execute luarocks make
to ensure you've installed the latest version.
Probably you have the latest sources but an older version locally installed.
I've tried using xml2lua.lua
directly, and also installing it using luarocks
, but I am still having the same issue. I'm not sure if the problem is on my side or not, but a workaround is super easy to implement, so this isn't really causing me any problems anymore!
If you provide an example, I check it here.
Here's a little example:
local xml2lua = require("xml2lua.xml2lua")
local table = {
person = {
{
name = "Carl",
city = "New York"
},
{
name = "Alex",
city = "London"
}
}
}
print(xml2lua.toXml(table, "people"))
Result:
<people>
<person>
<city>New York</city>
<name>Carl</name>
</person>
<person>
<city>London</city>
<name>Alex</name>
</person>
My local copy of xml2lua has this xml2lua-1.4-2.rockspec
:
package = "xml2lua"
version = "1.4-2"
source = {
url = "git://github.com/manoelcampos/xml2lua",
tag = "v1.4-2"
}
description = {
summary = "An XML Parser written entirely in Lua that works for Lua 5.1+",
detailed = [[
Enables parsing a XML string into a Lua Table and
converting a Lua Table to an XML string.
]],
homepage = "http://manoelcampos.github.io/xml2lua/",
license = "MIT"
}
dependencies = {
"lua >= 5.1, <= 5.4"
}
build = {
type = "builtin",
modules = {
xml2lua = "xml2lua.lua",
XmlParser = "XmlParser.lua",
["xmlhandler.tree"] = "xmlhandler/tree.lua",
["xmlhandler.print"] = "xmlhandler/print.lua",
["xmlhandler.dom"] = "xmlhandler/dom.lua",
}
}
That was an issue with the second param, which is optional. Just fixed that. Try the new 1.4-3 version. Thanks for reporting.
No problem! I will use the latest version.
Hi! Thank you so much for this amazing library. I have encountered another little problem with adding a
tableName
inxml2lua.toXml(table, tableName)
:Calling
xml2lua.toXml(table, "Game")
yields this result:Notice how the closing
</Game>
tag is missing.Thank you!
v1.4-2