2012-07-17 1 views
0

YouTube 데이터 API에서 제공하는 YouTube 피드를 구문 분석하려고합니다. 이 피드는 모든 동영상 uploaded by a specific user을 다음과 같이 나열합니다. https://gdata.youtube.com/feeds/api/users/google/uploads?v=2Parse youtube api feed v2

iOS 앱에서 touchXML을 사용하고 있습니다. 모든 <entry> 노드를 CXMLDocument의 nodesForXPath 함수를 사용하여 수집하려고했습니다.

NSURL *url = [NSURL URLWithString: newsFeedUrl]; 
CXMLDocument *feedParser = [[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil]; 
NSArray *resultNodes = [feedParser nodesForXPath:@"//entry" error:nil]; 
NSLog(@"%@",resultNodes.count); // >>> return (null) 

하지만이 쿼리는 아무 것도 반환하지 않습니다. xpath 구문을 확인했습니다. 나는 그것이 틀렸다고 생각하지 않는다.

답변

0

문제점을 발견했습니다. 그것은 Xpath와 네임 스페이스에 관한 것입니다. xpath를 사용하여 XML 문서를 구문 분석하려면 지원하려는 각 네임 스페이스에 대한 기본 매핑을 만들어야합니다.

NSDictionary * maps = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"http://www.w3.org/2005/Atom",@"http://search.yahoo.com/mrss/",@"http://a9.com/-/spec/opensearch/1.1/",@"http://schemas.google.com/g/2005",@"http://gdata.youtube.com/schemas/2007",@"W/\"C08MQXg-cSp7I2A9WhJRFEs.\"",nil] forKeys:[NSArray arrayWithObjects: @"ns",@"media",@"openSearch",@"gd",@"yt",@"etag",nil]]; 
NSArray *resultNodes = [feedParser nodesForXPath:@"//ns:entry" namespaceMappings:maps error:nil]; 

TouchXML에 대한 자세한 설명이 여기에 있습니다. 게시물을 찾았습니다. GDataXML 유용 할 수도 있습니다.