Hi helpful Applescripters!
I’d appreciate your advice. How would be the best way to create a list of lists from an XML file
I started off with the following hard coded list representing the XML tree, but thought it would be better to try and re-create it from the actual supplied XML file.
set theList to {{"Parent_1", {"Child_1", "Child_2", "Child_3"}}, {"Parent_2", {"Child_1", "Child_2", "Child_3"}}, {"Parent_3", {{"Child_1", {"GrandChild_1", "GrandChild_2", "GrandChild_3"}}, {"Child_2", {"GrandChild_1", "GrandChild_2", "GrandChild_3"}}, {"Child_3", {{"GrandChild_1", {"Great_GrandChild_1"}}}}}}}
This kind of belongs in the Xcode forum as well, as what I am trying to do is create an outline view from the structure of an XML file.
on createStructureFromLists(theList, parentItem)
repeat with a_subList in theList
set Chld_data_item to make new data item at end of data items of parentItem
if class of a_subList is text then
set contents of data cell "Item" of Chld_data_item to a_subList
set contents of data cell "Identity" of Chld_data_item to (contents of data cell "Identity" of parentItem) & "/" & a_subList
else
set contents of data cell "Item" of Chld_data_item to (item 1 of a_subList)
set contents of data cell "Identity" of Chld_data_item to (contents of data cell "Identity" of parentItem) & "/" & (item 1 of a_subList)
my createStructureFromLists((item 2 of a_subList), Chld_data_item)
end if
end repeat
end createStructureFromLists
I am getting really confused at the moment, as it seems I have to start from the inside of the structure and work outwards. Is there an easier way and have I approached this all wrong? As the above handler works to create the outline view, I thought it would be easier to re-create the list I used to create the outline view, but if it is easier, I could create the outline view as I am parsing the XML.
I would be grateful for any help
Cheers
Ian