私が達成しようとしているのは、 を使用して RSS2 フィード項目の src 属性を取得することですGDataXML
。フィードのアイテム xml は次のようになります。
<item>
<title>BlackBerry EMEA servers crash</title>
<link>http://www.mysite.com/?p=672</link>
<comments>http://www.mysite.com/?p=672#comments</comments>
<pubDate>Mon, 10 Oct 2011 21:11:24 +0000</pubDate>
<dc:creator>acreator</dc:creator>
<category><![CDATA[Latest News]]></category>
<description><![CDATA[<span class="image-rss"><a href="http://www.mysite.com/?p=672"><img title="BlackBerry EMEA servers crash" src="http://www.mysite.com/wp-content/uploads/2011/10/blackberry-thumb-medium-300x187.jpg" alt="BlackBerry EMEA servers crash" width="200" height="124" /></a></span><br/>yada yada yada]]></description>
</item>
私が現在使用しているコードは<description>
、 , <title>
, <link>
;をかなり細かく解析します。そして<pubdate>
; しかし失敗し<img>
ます;。コードは次のとおりです。
NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) {
NSArray *items = [channel elementsForName:@"item"];
for (GDataXMLElement *item in items) {
GDataXMLElement *articleDesc = [item elementForChild:@"description"];
NSArray *imgs = [articleDesc nodesForXPath:@"//img[@src]" error:nil];
NSString *articleTitle = [item valueForChild:@"title"];
NSString *url = [item valueForChild:@"link"];
NSString *articleDateString = [item valueForChild:@"pubDate"];
Article *entry = [[[Article alloc] initWithTitle:articleTitle
url:url
date:articleDate] autorelease];
[entries addObject:entry];
}
}
の説明をコンソールに出力するとarticleDesc
、次のようになります。
GDataXMLElement 0x70503b0: {type:1 name:description xml:"<description><span class="image-rss"><a href="http://www.mysite.com/?p=672"><img title="BlackBerry EMEA servers crash" src="http://www.mysite.com/wp-content/uploads/2011/10/blackberry-thumb-medium-300x187.jpg" alt="BlackBerry EMEA servers crash" width="200" height="124" /></a></span><br/>RIM has confirmed that…</description>"}
「高速」を使用してsrc
属性を解析することは可能GDataXML
ですか、それとも正規表現を使用して行う必要がありますか?
すべての提案は大歓迎です。