1

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 etc) 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...

ergosys
49.2k5 gold badges52 silver badges72 bronze badges
asked Jul 9, 2010 at 20:47

2 Answers 2

1

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

Abizern
152k41 gold badges209 silver badges260 bronze badges
answered Jul 9, 2010 at 21:04
Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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.

answered Jul 10, 2010 at 17:21

2 Comments

This might be useful for small xml files, but for larger files (more than a few megabytes), this will result in a large memory footprint. Some time ago, I had to do something similar and parsing the xml file significantly reduced the amount of memory the application used.
True enough but if you're talking Mac OS X, is anyone's library large enough for it to cause an actual issue? I doubt that.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.