2011-10-22 4 views
1

에서 나는처럼 보이는 HTML 데이터가 : 내가있는 tableView에 링크 제목을 보여줄 수있어구문 분석 HTML 데이터는 jQuery과

<div id="foo"><a class="someClass" href="http://somelink">Some Title</a></div> 
<div id="foo"><a class="someClass" href="http://somelink1">Some Title 1</a></div> 
<div id="foo"><a class="someClass" href="http://somelink2">Some Title 2</a></div> 

,하지만 어떻게 내가 새를로드 이러한 특정 제목의 URL을 얻을 수 있습니다 보기 (테이블 셀 선택시 네비게이션 컨트롤러를 통해 푸시)?

HTMLParser * parser = [[HTMLParser alloc] initWithData:responseData error:&error]; 
HTMLNode * bodyNode = [parser body]; 
someArray = [[bodyNode findChildrenWithAttribute:@"id" matchingName:@"someID" allowPartial:NO] retain]; 

그리고 테이블의 배열 데이터를 표시하려면이 하나 : 여기

내가 HTML 데이터를 구문 분석하는 데 사용하고 코드의

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [someArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    } 


    HTMLNode* someNode = [someArray objectAtIndex:[indexPath row]]; 
    cell.textLabel.text = [NSString stringWithFormat:@"%@",[someNode allContents]];  

    return cell;  
} 
+0

매우 가치있는 질문 ... 나는 또한 답변을 기다리고있다. –

답변

0

당신은 노드를 얻고 정보를 원하는 경우 그 안에있는 자식 노드에 관해서는, 계속 파싱하여 자식 노드를 찾은 다음 찾고있는 속성을 가져와야합니다. 예를 들어 :

HTMLNode *anchorNode = [someNode findChildTag:@"a"]; 
NSString *anchorHref = [anchorNode getAttributeNamed:@"href"]; 

그것은 당신이 Ben Reeves' HTMLParser보고있는 것을 언급 도움이 될 수 있습니다. (적어도 나는 그것이 당신이 사용하고있는 것이라고 생각한다).