Objective-c – Navigating XML from Objective-C

objective-cxml

I'm getting this XML response from TwitPic:

     <?xml version="1.0" encoding="UTF-8"?>
    <rsp stat="ok">
        <mediaid>abc123</mediaid>
        <mediaurl>http://twitpic.com/abc123</mediaurl>
    </rsp>

I want to access the value within the 'mediaurl' tags.

So I tried:

NSString *twitpicURL = [[request responseHeaders] objectForKey:@"mediaurl"];

But that doesn't seem to work.

Can someone point me in the right direction with this please?

Thanks,

Jamie.

Best Solution

Apple has NSXMLDocument (available on Mac OS X only) and NSXMLParser (available on Mac OS X and iPhone) both are based on the open source C library Libxml2 (available on Mac OS X and iPhone).

If you decide to use NSXMLDocument I would suggest using XPath as a quick/simple way to get the data.