I have a Xml parser which gives me a really deep structured table - but each level is based on same structure
Attributes = {
id = "main"
}
Name = "g"
ChildNodes = {
[1] = {
Attributes = { id = "FredFeuerstein" }
Name = "g"
ChildNodes = {
[1] = {
Attributes = {
id = "ShapeOfFred"
}
Name = ""
ChildNodes = {}
}
[2] = {...}
}
}
[2] = {
Attributes = { id = "Lol" }
Name = "..."
ChildNodes = {...}
}
} |
As you can see it has this structure, which is nested within each ChildNodes={}
table = {
Attributes = {}
Name = ""
ChildNodes = {...}
} |
How can I iterate through all of the items and make a new table out of it, that look similar to this:newTable = {
main = {
FredFeuerstein = {
ShapeOfFred = { ... }
}
Lol = { ... }
}
} |
Basically I want to take the
id from
Attributes in each level of depth and if it has
ChildNodes then subordinate them into the newly created node in my
newTable. Do you understand how I mean this? I just want to iterate through the whole big table with all those depths (which can be a lot: at least 2 levels) and take out the id's.
I was able to iterate through 2 levels of depth, but not all... I didn't managed to get a recursive function.. I don't know why...
How can I do this in Lua? I tried a lot and googled for 2 days, but it seems that I'm to stupid at the moment for this task, so please help!
--cheers
jack0088
Comments
Likes: atilim
PS:how did you get the self references into the table?
Thank you very much so far and sorry, for my lack of knowledge...
»Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
Likes: gorkem
»Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!