Closed pr-apes closed 1 year ago
What would the XML file look like from the CSV table?
The CSV is like this:
{
[1] = {
[1] = "a"
[2] = ""
},
[2] = {
[1] = ""
[2] = "b"
},
[3] = {
[1] = "c"
[2] = ""
},
},
I can't see what XML structure this could be. Perhaps I misunderstand the problem.
Sorry for the noise, @pgundlach.
I totally forgot that I had to name every element in the resulting XML file, so that the filter should read:
local runtime = require("runtime")
local csv = require("csv")
local xml = require("xml")
local csvtab, msg = csv.decode(runtime.variables["csv_file"])
if not csvtab then
print(msg)
os.exit(-1)
else
csvtab._name = "data"
for i=1,#csvtab do
csvtab[i]._name = "row"
for j=1,#csvtab[i] do
val = csvtab[i][j]
csvtab[i][j] = { _name = "cell", val }
end
end
local ok, err = xml.encode_table(csvtab)
if not ok then
os.exit(-1)
end
end
Sorry for the noise again. Closing the issue myself.
No problem.
I was thinking about automatically adding _name="cell"
etc. to the table so that it can be exported like in your example, but that would require a different table layout. So I think the intermediate step to create a new table is necessary.
Many thanks for the explanation about the requirement for the new table.
@pgundlach,
I have the following contents in a CSV file:
I have the following filter:
Invoking
sp --dummy --filter=filter.lua -v csv_file=file.csv
, I get the following error message and no conversion:I guess empty cells are the root of the problem.
Would it be possible that empty cells won't prevent table export to XML file?
Many thanks for your help.