2014-06-16 4 views
0

내 앱에서는 Wordpress RSS 피드의 XML에서 'title', 'link', 'pubDate'및 'description'과 같은 데이터를 구문 분석합니다. RSS 피드에 대한 설명에는 추천 이미지 링크와 설명이 이어집니다. 텍스트 필드에 설명 만 넣고 이미지보기에는 이미지를 넣고 싶습니다. 유일한 문제는 내 기존 NSXMLParser 내부에 HTML 파서를 구현해야합니까 아니면 더 간단한 방법입니까? NSXMLParser 내에서이 작업을 수행 할 수 있습니까? NSXMLParser 코드를 기존RSS 피드에 대한 설명 분석

<item> 
<title>Back-to-school issue of Blue and Gold in the mail</title> 
<link>http://cazhigh.com/caz/gold/?p=2896</link> 
<comments>http://cazhigh.com/caz/gold/?p=2896#comments</comments> 
<pubDate>Thu, 29 Aug 2013 12:35:40 +0000</pubDate> 
<dc:creator>...</dc:creator> 
<category>...</category> 
<category>...</category> 
<category>...</category> 
<guid isPermaLink="false">http://cazhigh.com/caz/gold/?p=2896</guid> 
<description> 
<![CDATA[ 
<img width="150" height="150" src="http://cazhigh.com/caz/gold/wp-content/uploads/2013/08/BluGold_BacktoSchool2013_cover-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Blue and Gold (Back to School 2013)" style="display: block; margin-bottom: 5px; clear:both;" />Be on the lookout for the September 2013 edition of the Blue and Gold newsletter, which should be arriving in the mail soon. Included in the newsletter are district policies and notifications that we urge you to review, become familiar with and keep for your reference throughout the school year. The issue also provides some [&#8230;] 
]]> 
</description> 
<content:encoded> 
<![CDATA[ 
<img width="150" height="150" src="http://cazhigh.com/caz/gold/wp-content/uploads/2013/08/BluGold_BacktoSchool2013_cover-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="Blue and Gold (Back to School 2013)" style="display: block; margin-bottom: 5px; clear:both;" /><div id="attachment_2898" style="width: 241px" class="wp-caption alignright"><a href="http://cazhigh.com/caz/gold/wp-file-browser-top/blueandgold/Blue%20and%20Gold%20(September%202013)"><img class="size-medium wp-image-2898 " alt="Blue and Gold (Back to School 2013)" src="http://cazhigh.com/caz/gold/wp-content/uploads/2013/08/BluGold_BacktoSchool2013_cover-231x300.jpg" width="231" height="300" /></a><p class="wp-caption-text">Blue and Gold (Back to School 2013)</p></div> <p itemprop="name"><span style="font-size: 13px;">Be on the lookout for the September 2013 edition of the Blue and Gold newsletter, which should be arriving in the mail soon. </span></p> <div itemprop="description articleBody"> <p>Included in the newsletter are district policies and notifications that we urge you to review, become familiar with and keep for your reference throughout the school year.</p> <p>The issue also provides some updates on work undertaken in Cazenovia schools — on everything from curricula to facilities — over the summer break, as well as &#8220;welcome back&#8221; messages from Superintendent of Schools Robert S. Dubik, Cazenovia High School Principal Eric Schnabl and Assistant Principal Susan Vickers, Cazenovia Middle School Principal Jean Regan and Burton Street Elementary Principal Mary-Ann MacIntosh.</p> <p>If you have questions related to the policies or notifications included in the newsletter, please call the district office at (315) 655-1317.</p> <p>The newsletter is also <span style="color: #000080;"><a title="link to Blue and Gold (September 2013)" href="http://cazhigh.com/caz/gold/wp-file-browser-top/blueandgold/Blue%20and%20Gold%20(September%202013)" target="_blank"><span style="color: #000080;"><b>available online</b></span></a></span>.</p> </div> 
]]> 
</content:encoded> 
<wfw:commentRss>http://cazhigh.com/caz/gold/?feed=rss2&p=2896</wfw:commentRss> 
<slash:comments>0</slash:comments> 
</item> 

:

XML 여기

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict; 
{ 

    classelement=elementName; 

    if([elementName isEqualToString:@"item"]) 
    { 
     itemselected=YES; 
     mutttitle=[[NSMutableString alloc] init]; 
     mutstrlink=[[NSMutableString alloc] init]; 
     mutstrdate=[[NSMutableString alloc] init]; 
     mutstrdesc=[[NSMutableString alloc] init]; 
    } 
} 

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName; 
{ 
    if([elementName isEqualToString:@"item"]) 
    { 
     itemselected=NO; 

     [titarry addObject:mutttitle]; 
     [linkarray addObject:mutstrlink]; 
     [datearray addObject:mutstrdate]; 
     [descarray addObject:mutstrdesc]; 

    } 

} 


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string; 
{ 
    if (itemselected) 
    { 

     if ([classelement isEqualToString:@"title"]) 
     { 
      [mutttitle appendString:string]; 
     } 
     else if ([classelement isEqualToString:@"link"]) 
     { 
      [mutstrlink appendString:string]; 
     } 
     else if ([classelement isEqualToString:@"pubDate"]) 
     { 
      [mutstrdate appendString:string]; 
     } 
     else if ([classelement isEqualToString:@"description"]) 
     { 
      [mutstrdesc appendString:string]; 
     } 

    } 
} 

답변

2

당신은 imageString 지금 http://cazhigh.com/caz/gold/wp-content/uploads/2013/08/BluGold_BacktoSchool2013_cover-150x150.jpg입니다

NSString *string = @"<![CDATA[<img width=\"150\" height=\"150\" src=\"http://cazhigh.com/caz/gold/wp-content/uploads/2013/08/BluGold_BacktoSchool2013_cover-150x150.jpg\" class=\"attachment-thumbnail wp-post-image\" alt=\"Blue and Gold (Back to School 2013)\" style=\"display: block; margin-bottom: 5px; clear:both;\" />Be on the lookout for the September 2013 edition of the Blue and Gold newsletter, which should be arriving in the mail soon. Included in the newsletter are district policies and notifications that we urge you to review, become familiar with and keep for your reference throughout the school year. The issue also provides some [&#8230;]]]>"; 

NSScanner *scanner = [NSScanner scannerWithString:string]; 
NSString *imageString, *otherSthing, *descriptionString; 
[scanner scanUpToString:@"src=\"" intoString:nil]; 
[scanner scanString:@"src=\"" intoString:nil]; 
[scanner scanUpToString:@"\"" intoString:&imageString]; 
[scanner scanUpToString:@"]]>" intoString:&otherSthing]; 
descriptionString = [otherSthing componentsSeparatedByString:@">"].lastObject; 

이동합니다.

descriptionString은 Be on the lookout for the September 2013 edition of the Blue and Gold newsletter, which should be arriving in the mail soon. Included in the newsletter are district policies and notifications that we urge you to review, become familiar with and keep for your reference throughout the school year. The issue also provides some [&#8230;]

입니다.