Need some advice on XML Parsing


#1

Hi there

This is a great starter for parsing XML… but I’ve got a more complex XML stream I’d like to parse out… specifically it’s from “http://mayfarers.blip.tv/rss” … I need to grab the “title” and the URL for the iphone compatible video stream, which I think is the URL attribute of the media:content element, as well as maybe the thumbnail.

Basically I want to write a simple app that allows me to view blip.tv stream episodes on the iphone to reinforce what I learned here.

I dont see how to grab an attribute under an element… has anyone done this? Is there maybe an alternative to NSXMLParser?

<media:content blip:acodec="ffaac" blip:role="Blip SD" blip:vcodec="ffh264" expression="full" fileSize="33014695" height="358" isDefault="false" type="video/x-m4v" url="http://blip.tv/file/get/Mayfarers-MayfarersGoHollywood2488.m4v" width="640"></media:content>

The title isnt a problem… and I can throw that up in a table (grab.by/9Q6m) its just

<title>Mayfarers Go Hollywood</title>

Here’s the full XML

<item>
  <guid isPermaLink="false">B5EAED00-547C-11E0-B798-C5453A46DF68</guid>
  <link>http://blip.tv/file/4917218</link>
  [b]<title>Mayfarers Go Hollywood</title>[/b]
  <blip:user>mayfarers</blip:user>
  <blip:userid>336212</blip:userid>
  <blip:safeusername>mayfarers</blip:safeusername>
  <blip:show>Meet the Mayfarers</blip:show>
  <blip:showpage>http://www.mayfarers.com</blip:showpage>
  <blip:picture>/Mayfarers-picture263.jpg</blip:picture>
  <blip:posts_id>4935141</blip:posts_id>
  <blip:item_id>4917218</blip:item_id>
  <blip:item_type>file</blip:item_type>
  <blip:contentRating>TV-UN</blip:contentRating>
  <blip:rating>0.0</blip:rating>
  <blip:datestamp>2011-03-22T12:05:42Z</blip:datestamp>
  <blip:language>English</blip:language>
  <blip:adChannel>Comedy</blip:adChannel>
  <blip:recommendations>0</blip:recommendations>
  <blip:recommendable>0</blip:recommendable>
  <blip:core>0</blip:core>
  <blip:adminRating>2</blip:adminRating>
  <blip:runtime>330</blip:runtime>
  <blip:embedLookup>hvw1gq2cSQI</blip:embedLookup>
  <blip:embedUrl type="application/x-shockwave-flash">http://blip.tv/play/hvw1gq2cSQI</blip:embedUrl>
  <wfw:commentRss>http://blip.tv/comments/?attached_to=post4935141&amp;skin=rss</wfw:commentRss>
  [b]<blip:thumbnail_src>Mayfarers-MayfarersGoHollywood670.png</blip:thumbnail_src>[/b]
  <blip:puredescription><![CDATA[Nick gets a new agent, and travels to Hollywood. Guest starring the Creators of "Life From the Inside" and "Vampire Zombie Werewolf!"]]></blip:puredescription>
  <blip:smallThumbnail>/Mayfarers-MayfarersGoHollywood670-568.jpg</blip:smallThumbnail>
  <blip:license>No license (All rights reserved)</blip:license>
  <blip:categories>
    <blip:category>comedy</blip:category>
    <blip:category>fhsitcoms</blip:category>
  </blip:categories>
  <description><![CDATA[

<embed src="http://blip.tv/play/hvw1gq2cSQI" type="application/x-shockwave-flash" width="480" height="299" allowscriptaccess="always" allowfullscreen="true"></embed>
<br />

Nick gets a new agent, and travels to Hollywood.<br />
 Guest starring the Creators of "Life From the Inside" and "Vampire Zombie Werewolf!"<br />
<br />


]]></description>
  <comments>http://blip.tv/file/4917218</comments>
  <category>Comedy</category>
  <category>season 3</category>
  <category>episode 5</category>
  <category>todd norwood</category>
  <category>mayfarers</category>
  <category>comedy</category>
  <category>hollywood</category>
  <category>lfti</category>
  <category>robb padgett</category>
  <category>tanya ihnen</category>
  <category>steve lekowicz</category>
  <pubDate>Tue, 22 Mar 2011 12:05:42 +0000</pubDate>
  <enclosure length="116497367" type="video/quicktime" url="http://blip.tv/file/get/Mayfarers-MayfarersGoHollywood350.mov"/>
  <itunes:keywords>season 3, episode 5, todd norwood, mayfarers, comedy, hollywood, lfti, robb padgett, tanya ihnen, steve lekowicz</itunes:keywords>
  <itunes:image>/Mayfarers-MayfarersGoHollywood670.png</itunes:image>
  <media:keywords>season 3, episode 5, todd norwood, mayfarers, comedy, hollywood, lfti, robb padgett, tanya ihnen, steve lekowicz</media:keywords>
  <media:group>
    <media:content blip:acodec="ffaac" blip:role="Source" blip:vcodec="ffh264" expression="full" fileSize="116497367" height="366" isDefault="true" type="video/quicktime" url="http://blip.tv/file/get/Mayfarers-MayfarersGoHollywood350.mov" width="651">
      <mediaad:content exc="0" position="preroll" pro="1.0" provider="freewheel" was_blend="1" wgt="1.0"/>
      <mediaad:content exc="0" position="preroll" pro="1.0" provider="scanscoutbranded" was_blend="1" wgt="1.0"/>
      <mediaad:content duration="15" exc="0" position="overlay" pro="1.0" provider="freewheel" start="5" was_blend="1" wgt="1.0"/>
      <mediaad:content duration="15" exc="0" position="overlay" pro="1.0" provider="scanscout" start="5" was_blend="1" wgt="1.0"/>
      <mediaad:content duration="15" exc="0" position="overlay" pro="1.0" provider="google" start="5" was_blend="1" wgt="1.0"/>
      <mediaad:content duration="15" exc="0" position="overlay" pro="1.0" provider="googlebranded" start="5" was_blend="1" wgt="1.0"/>
      <mediaad:content duration="15" exc="0" position="overlay" pro="1.0" provider="scanscoutbranded" start="5" was_blend="1" wgt="1.0"/>
    </media:content>
    [b]<media:content blip:acodec="ffaac" blip:role="Blip SD" blip:vcodec="ffh264" expression="full" fileSize="33662059" height="358" isDefault="false" type="video/x-m4v" url="http://blip.tv/file/get/Mayfarers-MayfarersGoHollywood699.m4v" width="640"></media:content>[/b]
  </media:group>
  <media:player url="http://blip.tv/file/4917218"><![CDATA[<embed src="http://blip.tv/play/hvw1gq2cSQI" type="application/x-shockwave-flash" width="480" height="299" allowscriptaccess="always" allowfullscreen="true"></embed>]]></media:player>
  <media:title>Mayfarers Go Hollywood</media:title>
  <media:thumbnail url="/Mayfarers-MayfarersGoHollywood670.png"/>
</item>

#2

Okay, I’m an idiot I found the answer. I just need to look through the attribute dictionary :slight_smile:

#pragma mark NSXMLParserDelegate
- (void) parser:(NSXMLParser *)parser 
didStartElement:(NSString *)elementName 
   namespaceURI:(NSString *)namespaceURI 
  qualifiedName:(NSString *)qName 
	 attributes:(NSDictionary *)attributeDict{
	
	if ([elementName isEqual:@"media:content"] && waitingForEntryTitle) {
		NSString *url = [attributeDict objectForKey:@"url"];
		NSLog(@"Fount a URL Attribute of a media:content element >>%@<<",url);
	}
}