我懷疑這是XML命名空間的問題。根據使用的框架和實際完整的XML,您必須通過名稱空間訪問元素。您可能想切換到另一個基於DOM的框架(不使用NSXMLParser
),例如Google提供的GDataXMLNode。在基於DOM的框架中,您可以以樹狀結構訪問各個節點,而不是單獨構建一個節點。
網上有很多這方面的例子,例如Building an RSS reader或How to read and write XML documents with GDataXML。但是,給一個簡單的例子如何看起來:
NSError *error = nil;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];
if (doc == nil) { return nil; }
NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
NSArray *lists = [doc nodesForXPath:@"/result/list" error:nil];
if ([lists count] > 0)
{
for (GDataXMLNode *list in lists) {
int listid = [self integerInNode:list forXPath:@"listid"];
NSString *listname = [self stringInNode:list forXPath:@"name"];
[result setValue:[NSNumber numberWithInt:listid] forKey:listname];
}
}
[doc release];
return [result autorelease];
首先感謝您的重播,和我很抱歉,因爲我編輯的職位,並做出反應不與它有關,但我做到這一點,因爲在頁面中的錯誤,我explane:我寫我的問題(但我沒有點擊「發佈你的問題」),但我找到了一個解決方案,有一個JSON的聽衆,所以我刪除了我寫後,不可能發佈,我有一個錯誤消息說:「不在我們的標準」。再次抱歉。我張貼原帖她:我的問題是,nsxmlparser不能解析這樣的 –