Closed pr-apes closed 1 year ago
Does this help?
local xml = require("xml")
dofile("debug.lua")
ok ,tab = xml.decode_xml("data.xml")
printtable("data",tab)
data.xml:
<root>
<child>1</child>
<child>2</child>
<child><abc>abc</abc></child>
</root>
lua table:
data = {
[1] = "\n "
[2] = {
[1] = "1"
["_type"] = "element"
["_name"] = "child"
},
[3] = "\n "
[4] = {
[1] = "2"
["_type"] = "element"
["_name"] = "child"
},
[5] = "\n "
[6] = {
[1] = {
[1] = "abc"
["_type"] = "element"
["_name"] = "abc"
},
["_type"] = "element"
["_name"] = "child"
},
[7] = "\n"
["_type"] = "element"
["_name"] = "root"
}
(formatting is a bit broken)
the table above is the second argument of xml.decode_xml()
Sorry for the delayed reply, @pgundlach.
I have to check this later, but I have a comment.
I cannot use dofile("debug.lua")
unless full path is specified. I wonder whether this is intended.
Many thanks for your help.
This works for me where debug.lua is in the current directory.
I will close this as fixed. If there are still problems, please re-open.
It works for me with current version (4.13.12) as require("debug")
.
Is this the standard way of invoking it?
Actually I am not a Lua expert regarding dofile()
and require()
. I use dofile("debug.lua")
for my debugging script, but require could also work.
In my case, require()
seems to find the file in the Publisher tree.
dofile()
requires full path and extension to find the file.
From Programming in Lua (first edition), section 8.1 – The require
Function (https://www.lua.org/pil/8.1.html):
Lua offers a higher-level function to load and run libraries, called
require
. Roughly, require does the same job asdofile
, but with two important differences. First,require
searches for the file in a path; second,require
controls whether a file has already been run to avoid duplicating the work. Because of these features,require
is the preferred function in Lua for loading libraries.
@pgundlach,
I read in the documentation about
decode_xml()
:Is there any way to influence the table name? At least, which is the name of the imported table?
I'm afraid imported XML data are of no use in the filter, unless I can access them.
Sorry, but I guess either the documentation or myself lacks something.
Many thanks for your help.