1
我正在使用普通的XML解析器並將XML的值存儲在字典中。什麼時候XML解析在iPhone應用程序中完成?
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"CountryId"]){
currentTweet.content = currentNodeContent;
[data setObject:currentTweet.content forKey:@"CountryId"];
//NSLog(@"currentNode is %@",currentNodeContent);
}
if([elementName isEqualToString:@"CountryName"]){
currentTweet.createdAt = currentNodeContent;
[data setObject:currentTweet.createdAt forKey:@"CountryName"];
//NSLog(@"currentNode is countnry Name %@",currentNodeContent);
}
/*if([elementName isEqualToString:@"Country"]){
[tweets addObject:currentTweet];
tweet *current = [tweets objectAtIndex:0];
NSLog(@"value of current is %@",current.content);
NSLog(@"value of Country tweet is %@",current.createdAt);
[currentTweet release];
currentTweet = nil;
[currentNodeContent release];
currentNodeContent = nil;
}*/
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
我想了解一些方法,它告訴我,當XML數據是完全讀取並存儲在數組中。我使用這些方法通過Web代理方法,因爲我來自視野肥皂讀取數據並加載整理我的XML傳遞給XML解析器是這樣的:
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSLog(@"recived data %@",webData);
NSString *theXML = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
//---shows the XML---
NSLog(@"%@",theXML);
[theXML release];
if(xmlParser)
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
//[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
[connection release];
[webData release];
}
' - (空)parserDidEndDocument :(的NSXMLParser *)解析器 { \t的NSLog(@ 「parserDidEndDocument」); }' – dark 2011-02-25 04:56:22
我已經寫了函數結束了,但是這裏先調用的是oput放的函數: – dark 2011-02-25 04:57:16
[會話開始於2011-02-25 09:53:22 +0500。] 2011-02- 25 09:53:24.616 TwitterDemo [1327:207] parserDidEndDocument 2011-02-25 09:53:24.617 TwitterDemo [1327:207]拿督:太陽5月25日9時52分11秒+0000 2008 MED innhold的Webkit/Chrome開發者工具從谷歌演示I/O:http://t.co/4kpLg8N 2011-02-25 09:53:24.618 TwitterDemo [1327:207]拿督:太陽5月25日 – dark 2011-02-25 04:58:47