2011-03-12 2 views
0

ATOM 형식 데이터를보다 정확하게 XLM 문서 구문 분석과 관련하여 질문이 있습니다. (RSS 피드).RSS 피드 XML 및 ATOM 구문 분석 문제 - GData - iPhone

NSArray *channels = [rootElement elementsForName:@"channel"]; 
for (GDataXMLElement *channel in channels) 
{    

    NSString *blogTitle = [channel valueForChild:@"title"];      

    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"];   
     NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822]; 



     RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle 
                articleTitle:articleTitle 
                articleUrl:articleUrl 
                articleDate:articleDate] autorelease]; 
     [entries addObject:entry];       

    }  
} 

내가 미디어를 검색하는 방법을 모른다 : 이것은 내가 제목을 구문 분석하는 방법, pubDate의 링크 값은

<item> 
      <title>Panty + Stocking Print Preview</title> 
      <link>http://SonicRocksMySocks.deviantart.com/art/Panty-Stocking-Print-Preview-200615179</link> 
      <guid isPermaLink="true">http://SonicRocksMySocks.deviantart.com/art/Panty-Stocking-Print-Preview-200615179</guid> 
      <pubDate>Fri, 11 Mar 2011 21:43:34 PST</pubDate> 
      <media:title type="plain">Panty + Stocking Print Preview</media:title> 

      <media:keywords></media:keywords> 
      <media:rating>nonadult</media:rating> 
      <media:category label="Movies &amp; TV">fanart/digital/drawings/movies</media:category> 
      <media:credit role="author" scheme="urn:ebu">SonicRocksMySocks</media:credit> 
      <media:credit role="author" scheme="urn:ebu">http://a.deviantart.net/avatars/s/o/sonicrocksmysocks.png?15</media:credit> 
      <media:copyright url="http://sonicrocksmysocks.deviantart.com">Copyright 2011 *SonicRocksMySocks</media:copyright> 
      <media:thumbnail url="http://th00.deviantart.net/fs71/300W/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" height="351" width="300"/> 

      <media:thumbnail url="http://th02.deviantart.net/fs71/150/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" height="150" width="128"/> 
      <media:content url="http://th08.deviantart.net/fs71/PRE/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" height="967" width="826" medium="image"/> 
      <media:content url="http://www.deviantart.com/download/200615179/" medium="document"/> 
      <description><![CDATA[ The final version of this print will be available for sale at Sakura Con 2011. :3<br /><div><img src="http://th00.deviantart.net/fs71/300W/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" alt="thumbnail" /></div> ]]></description> 
      <media:description type="html"><![CDATA[ The final version of this print will be available for sale at Sakura Con 2011. :3 ]]></media:description> 
     </item> 

: 여기

는 XLM 문서의 샘플입니다 : 콘텐츠 라인. 내가 어떻게 해? 아무도 도와 줄 수 있습니까?

당신에게 많이 감사 안드레이

+0

글쎄요, 어떤 라이브러리를 사용하고 있는지 잘 모르겠지만 XML 소스에있는 모든 것으로 미디어 접두어의 네임 스페이스를 정의하고 싶을 것입니다 (문서의 루트 요소를 확인하십시오. 거기에'xmlns' 속성이 있습니다.) 어떻게 든 GDataXMLElement에 저장 한 다음 검색의 일부로 사용하십시오. GDataXML 요소에 대해 더 많이 알고있는 사람, 그 라이브러리가있는 라이브러리가 무엇이든 더 명시적일 수 있습니다. –

답변

0

당신이 item의 아이들을 반복하고 디버거 또는 NSLog에서 그들을 검사 봤어로 NSXMLParsing를 사용해보십시오?

+0

감사합니다.하지만 내가하는 쇼에 대해 설명해주십시오. 나는 초보자 일종이다 –

+0

NSLog (@ "% @", 항목) 추가 시도; for 루프의 시작 부분 근처. 콘솔에서 유용한 출력을 얻을 수 있습니다. – koregan

+0

이전에 게시 한 XLM 코드와 동일합니다. –

0

먼저 u는이 간단한 튜토리얼

http://blancer.com/tutorials/i-phone/76999/parsing-xml-files/ 
0

사용중인 코드를 알고 있습니다. 사실 아주 간단합니다. 당신은 당신이 "제목"과 "링크"와 "pubDate"를 얻는 것과 같은 방식으로 그것을합니다.

NSArray *channels = [rootElement elementsForName:@"channel"]; 
for (GDataXMLElement *channel in channels) 
{    

NSString *blogTitle = [channel valueForChild:@"title"];      

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"];   
    NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822]; 

    // Right here 
    NSString *mediaCont = [item valueForChild:@"media:content"]; 



    RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle 
               articleTitle:articleTitle 
               articleUrl:articleUrl 
               articleDate:articleDate] autorelease]; 
    [entries addObject:entry];       

}  
} 

그런 다음이 새로운 필드를 허용하도록 RSSEntry 용 init 메소드를 변경해야합니다. valueForChild를 정의하는 코드를 살펴보고 GDataXML 파서를 사용하는 방법을 확인해야합니다. 또는 제안 된대로 NSXML을 사용할 수도 있습니다.