The structure you will receive from the XML lib for each of your two files is something like
{
library =
{
gametype1 =
{
category =
{
{ -- category[1]
name="name1",
answer = {"ans1", "ans2", "ans3"}
},
{ -- category[2]
name="name2",
answer = {"ans1", "ans2", "ans3"}
},
}
},
gametype2 =
{
category =
{
{ -- category[1]
name="name1",
answer = {"ans1", "ans2", "ans3"}
},
{ -- category[2]
name="name2",
answer = {"ans1", "ans2", "ans3"}
},
}
},
}
}
and you want to combine table1.library.gametype1 with table2.library.gametype1, and do the same for gametype2 of table1 and table2. Since you will not be changing the two tables after they are created, you don't need deep copy:
local function concat(fromTable, intoTable)
local lenFrom = #fromTable
for i = 1, lenFrom do
table.insert(intoTable, fromTable[i])
end
end
local gameAnswers1 = xml:loadFile( "file1.xml", system.ResourceDirectory )
local gameAnswers2 = xml:loadFile( "file2.xml", system.ResourceDirectory )
local gameType1A = gameAnswers1.library.gametype1
local gameType1B = gameAnswers2.library.gametype1
concat(gameType1B.category, gameType1A.category)
-- now table contains its categories plus all those of table2
local tableGameType1 = gameType1A
local gameType2A = gameAnswers1.library.gametype2
local gameType2B = gameAnswers2.library.gametype2
concat(gameType2B.category, gameType2A.category)
-- now table1 contains its categories plus all those of table2
local tableGameType2 = gameType2A
Just beware that gameAnswers1 now contains all categories from both files.