我正在使用NSXMLParser, 我使用以下代码存储在对象
中 - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
string = [string stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(element);
NSLog(string);
if(([string length]>0 )||([string isEqualToString:@"c_id"])){
// NSLog([NSString stringWithFormat:@"%@ %@",element,string]);
if([element isEqualToString:@"c_id"]){
if([string isEqualToString:@""]||string==NULL);
else
oneCharade.team_id=string;
}
else
if([element isEqualToString:@"title"]){
if([string isEqualToString:@""]||string==NULL);
else
oneCharade.title=string;
}
else
if([element isEqualToString:@"desc"]){
oneCharade.desc=string;
// NSLog(string);
//NSLog(oneCharade.desc);
[allCharades addObject:oneCharade];
//[app.itemData addObject:data];
// NSLog(@"Object is added %@",searchedData.pid);
}
}// end of the outer if
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
element=elementName;
if([element isEqualToString:@"c_id"]){
oneCharade=[[XMLTeamData alloc]init];
//NSLog(@"Object is created");
}
}// end of the did start Element
-(void)parserDidEndDocument:(NSXMLParser *)parser{
CharadesAppDelegate *del=(CharadesAppDelegate *)[[UIApplication sharedApplication]delegate];
[del setServerCharades:allCharades];
//NSLog(@" count :%i",[allCharades count]);
}
但是desc事件发生了两次,你可以看到以下
2011-11-29 11:49:31.251 Charades[741:207] c_id
2011-11-29 11:49:31.251 Charades[741:207] 191
2011-11-29 11:49:31.251 Charades[741:207] title
2011-11-29 11:49:31.251 Charades[741:207] Todd Philips
2011-11-29 11:49:31.251 Charades[741:207] desc
2011-11-29 11:49:31.251 Charades[741:207] Baksm
2011-11-29 11:49:31.251 Charades[741:207] desc
2011-11-29 11:49:31.251 Charades[741:207] ällan
你可以在这里看到
<c_id>191</c_id><title>Todd Philips</title><desc>Baksmällan</desc><category>Filmer</category>
但是描述的事件是发生设备,如何解决这个问题
答案 0 :(得分:1)
您的特殊字符ä
数据似乎存在问题。
您可以尝试<desc><![CDATA[Baksmällan]]></desc>
解析器将解析XML文档中的所有文本。但解析器将忽略CDATA部分内的文本。你可以找到更多here。
希望这有帮助。