Parsing PList files in ActionScript

The PList format is not one of my favorites. I've complained about it before, but Apple continues to use it for its iTunes library information, so I continue to parse it.

I've been exploring the option of porting the iTunesExport project to Flex (Air) to provide a cross platform version. The current version is written in .Net and therefore not usable on OS X. As such I needed to parse the PList file using ActionScript. I adopted the Java PList Parser written by Christoffer Lerno for his XMLWise project.

The dynamic nature of ActionScript resulted in a much smaller implementation (although I did skip over 'REAL' and 'DATA' types), and makes it easy to consume.

You can view or download my version here, released under the MIT license.

Here is a snapshot of how it is used:
var parser:PListParser = new PListParser();
var pList:Object = parser.parsePList(xml);

playlists = pList.Playlists.filter(filterPlaylists);
The last line accesses the Playlist array (dynamically created when the PList is parsed), and filters it using the specified filterPlaylists method, returning a filtered list of the playlists from the original XML file.

It provides easy structured access to an XML file that would otherwise be difficult to access in a rational manner.

No comments:

Post a Comment