Create List of Lists from XML tree

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

If you are using ASOC you might take a look at Using Tree Controllers With NSXML Objects

Thanks for the reply,

I’m not using ASOC, but the link you posted is exactly what I need - it’s just implementing it that’s going to take some figuring!
Presumably, is this something that could be called from applescript with a call method…? or is it more involved than that?
I’d still be interested in any vanilla AS or CLI methods, if anyone has done something like this before

Ian

I’m sorry, when I read Xcode and outline view I automatically assumed NSOutlineView.
How about the XML classes in System Events?

FWIW, this is a recent thread about conversion between XML/plists and AppleScript data structures.

Had a look through the ObjectiveC method linked to and I think it is a bit beyond me.

Also, if I allow the user to navigate the XML structure verbatim, there will be areas such as Name/Value pairs where it will not be obvious what to select, so I am going to have to go for more of a proprietary approach.

The application is for configuring xpath queries to get data out of a XML output from a database web service.
Thank you for taking the time to post suggestions

Ian