Re: Getting started with XML?
Re: Getting started with XML?
- Subject: Re: Getting started with XML?
- From: kai <email@hidden>
- Date: Sun, 11 Feb 2007 17:08:44 +0000
On 10 Feb 2007, at 10:26, Emmanuel wrote:
At 12:35 AM +0000 2/10/07, kai wrote:
On 8 Feb 2007, at 00:24, Luther Fuller wrote:
The only reliably safe method of reading a .plist file is to read
the whole file into a record, like this ...
etc ...
This thread seems a bit surrealistic if you once used XMLLib.osax
to handle plists. Just out of curiosity, Michelle, kai, Luther, did
you try to use XMLLib? Were you disappointed somehow?
Given that we were discussing techniques rather than solutions,
Emmanuel, my initial intention in this thread was just to demonstrate
a way to extract/parse a subset of data from a plist file. I think
you'll find that the above response (attributed but not quoted)
merely suggested that the use of appropriate tools should provide
more than one reasonably reliable way to achieve this.
Granted, my suggestions were vanilla flavoured - but then you can
normally be relied upon to promote the benefits of any Satimage-based
alternative. ;-) If that was the aim of your (presumably rhetorical)
question, then perhaps some sample code might help to make the point
even more compelling. While Satimage provides excellent online
tutorials on the general use of XMLLib, a specific example is (IMHO)
even more likely to encourage potential users.
Indeed, partly because XMLLib deals primarily with references,
comparisons and evaluation can normally be performed pretty quickly,
even when performed in a repeat loop. So instead of the technique
suggested in my last post, one might use something like:
-----------
-- requires XMLLib.osax:
-- http://www.satimage.fr/software/en/downloads_osaxen_pop.html
set plist_file to (choose file of type "public.xml" default location
(path to ¬
music folder) with prompt "Choose an iTunes xml file:" without
invisibles)
set plist_ref to PlistOpen plist_file
set track_list to PlistChild plist_ref key "Tracks"
set result_list to PlistGetKeys track_list
repeat with curr_item in result_list
set curr_track to PlistChild track_list key curr_item
set key_list to PlistGetKeys curr_track
if "Name" is in key_list then
set curr_item's contents to (PlistGet curr_track key "Name") & " - "
else
set curr_item's contents to " - "
end if
if "Artist" is in key_list then set curr_item's contents to ¬
curr_item & (PlistGet curr_track key "Artist")
end repeat
PlistClose plist_ref
result_list
-----------
To answer your question more directly, I've never yet been
disappointed by a Satimage offering. On the contrary, I regard them
all as fine products. However, that won't necessarily stop me from
suggesting a vanilla approach where I consider it reasonably viable -
being perfectly content to leave the advocacy of alternatives to
those more experienced than I in such matters. :-)
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden