I am trying to parse XML from an RSS feed.
It contains ATOM data and I would like to parse it using GData library.
The XML code looks like this:
<item>
<title>Madoka Kaname</title>
<link>http://emperpep.deviantart.com/art/Madoka-Kaname-200775806</link>
<guid isPermaLink="true">http://emperpep.deviantart.com/art/Madoka-Kaname-200775806</guid>
<pubDate>Sun, 13 Mar 2011 05:36:08 PDT</pubDate>
<media:title type="plain">Madoka Kaname</media:title>
<media:keywords></media:keywords>
<media:rating>nonadult</media:rating>
<media:category label="Paintings">manga/digital/paintings</media:category>
<media:credit role="author" scheme="urn:ebu">emperpep</media:credit>
<media:credit role="author" scheme="urn:ebu">http://a.deviantart.net/avatars/e/m/emperpep.jpg</media:credit>
<media:copyright url="http://emperpep.deviantart.com">Copyright 2011 *emperpep</media:copyright>
<media:thumbnail url="http://th08.deviantart.net/fs70/300W/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="389" width="300"/>
<media:thumbnail url="http://th09.deviantart.net/fs70/150/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="150" width="116"/>
<media:content url="http://fc05.deviantart.net/fs70/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="988" width="761" medium="image"/>
<media:content url="http://www.deviantart.com/download/200775806/" medium="document"/>
<description><![CDATA[ Digital Painting : Madoka KanamePicture of Madoka Kaname , made for an Anime convention.Tools:Sai 1.1.0 Photoshop CSWacom Intuos 3Macbook ProTime: 3 daysCharacters from Puella Magi Madoka Magica [...<br /><div><img src="http://th08.deviantart.net/fs70/300W/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" alt="thumbnail" /></div> ]]></description>
<media:description type="html"><![CDATA[ Digital Painting : Madoka KanamePicture of Madoka Kaname , made for an Anime convention.Tools:Sai 1.1.0 Photoshop CSWacom Intuos 3Macbook ProTime: 3 daysCharacters from Puella Magi Madoka Magica [... ]]></media:description>
</item>
I don't have any idea how to get the data contained in the media:content field. Can anyone help me with this one?
I found the answer. Here is the code:
NSArray *items = [channel elementsForName:@"item"];
for (GDataXMLElement *item in items)
{
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = [item valueForChild:@"link"];
NSString *articleDateString = [item valueForChild:@"pubDate"];
NSArray *mediaArray = [item elementsForName:@"media:content"]; //this is the code for what I needed
for (GDataXMLElement *content in mediaArray)
{
NSString *url = [[content attributeForName:@"url"] stringValue];
NSLog(@"URL: %@", url);
}
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate] autorelease];
[entries addObject:entry];
}