Creating Sockets, iTunes Music Store Queries, and S3 Followup

by Erica Sadun

A few days back, I offered to explain how I was using sockets to connect to Amazon's S3 service. A few people expressed interest in the comments and via email. In order to simplify the example (since the S3 service involves a lot of authentication), I decided to start with an iTunes Music Store query. This has the advantage of a very simple header where you just substitute in a search phrase as needed. And of course, you can do it by hand without programming to start with.

More details, how-to, mumbling and source code over at engeek.


2006-03-21 12:34:32
Your blog says "you must be logged in to post comments" when I try, but doesn't seem to offer a way to register. So here's what I wrote there:

You can do this even more easily using Cocoa's Foundation framework. Fetching and parsing the data takes two lines:

NSURL *url = [NSURL URLWithString: @"http://.........."];
NSXMLDocument *doc = [[NSXMLDocument alloc] initWithContentsOfURL: url options: 0 error: &error];

At this point you have an object 'doc' that represents the root node of the XML document. Walking around the node tree and grabbing data is pretty straightforward (see NSXMLNode.h). For even more powerful data-extraction you can use the XQuery language, also in Foundation.

(If you need more control over the HTTP request, like adding custom headers or authentication, you can use NSURLRequest and NSURLConnection to download the raw data, then pass that data to NSXMLDocument.)