views:

84

answers:

2

I'm working on an iTunes menu bar controller and I want to get the names of all the songs in the user's library. I have found that there is an xml file called iTunes Library.xml. It holds all the data for iTunes (name, artist, album .ect) I want to be able to access that data to use in my controller.

I really have never used xml for anything so go easy…

I am also a noob at objective-C so go REALLY easy…

+1  A: 

There are two things you are going to want to learn about to scan xml info. One is called xpath and the other is called xquery. On the surface they are both basically ways of creating a regular expression to grab different parts of xml data. Googling xpath should bring up many examples tor create any type of expression you can imagine. NSXMLParser is a Cocoa class that can create a parser object and has the method nodesForXPath which will take your xpath query gather the results and store them in an array.

Apple's dev docs here

Rick
NSXMLParser seems a bit overcomplicated. I believe this is just an archived NSDictionary. I doubt the file is so large you'd benefit from the parser work very much.
Joshua Nozzi
A: 

I'm pretty sure the iTunes XML library is an XML PLIST dictionary. You could save some headaches by reading up on NSDictionary and using the +dictionaryWithCintentsOf...: class method, then just navigating the structure by its keys.

If you open it with the Property List Editor app that comes with Xcode Tools, you can explore its structure visually, which will give you an idea how to navigate the dicts and arrays programmatically.

Joshua Nozzi