Transform Your iTunes Library File

Grab data out of your iTunes library file and transform it into HTML.

Apple’s iTunes (http://www.apple.com/itunes/) is a nifty application that allows you to purchase, store, organize, and play media on either the Mac or Windows. You can buy and download individual songs or whole albums from the iTunes Music Store, and then store them on your hard drive, burn them to CD, or load them into an iPod digital music player (http://www.apple.com/ipod/). Figure 3-22 shows the iTunes Music Store in the iTunes application in Windows.

iTunes Music Store

Figure 3-22. iTunes Music Store

One XML feature of iTunes is that you can save information about your music library in an XML file using the File Export Library command. This file is an example of the Apple Property List (plist) file format, common on Mac OS X systems. For example, the file ~/.MacOSX/environment.plist is a plist file in which a user’s environment variables are stored and that can be edited with the PropertyListEditor.app (see http://developer.apple.com/qa/qa2001/qa1067.html for an example).

In raw form, plist files can be long and hard to decipher. That’s where XSLT can help. This hack will show you how to transform your Library.xml plist file into HTML. A few lines of an instance of Library.xml (Version 4.2.0.72) are shown in Example 3-26.

Example 3-26. Library.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...

Get XML Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.