這是我的XML文件的例子的NSXMLParser問題標籤來清空
<head>
<cat>some title here...
<info>some info here
<summary>bla bla bla</summary>
<full>
the full text here
</full
</info>
</cat>
</head>
我使用NSXMLParserDelegate方法是這樣的:
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if (qName) {
elementName = qName;
}
// If it's the start of the XML, remove everything we've stored so far
if([elementName isEqualToString:@"head"])
{
[self emptyDataContext];
return;
}
else if([elementName isEqualToString:@"bgimage"])
{
enter code here
}
// Create a new Category
else if ([elementName isEqualToString:@"cat"])
{
//array catching the values
}
else if ([elementName isEqualToString:@"info"])
{
[add addObject:currentElementValue];
}
else if([elementName isEqualToString:@"summary"])
{
}
else if([elementName isEqualToString:@"full"])
{
}
else if([elementName isEqualToString:@"quote"])
{
}
如果有一個數組,捕捉從所有的值使用以下函數的當前字符串:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (!currentElementValue) {
// init the ad hoc string with the value
currentElementValue = [[[NSMutableString alloc] initWithString:string]autorelease];
} else {
// append value to the ad hoc string
[currentElementValue setString:string]; //appendString:string];
}
NSLog(@"Processing value for : %@", string);
}
由於某種原因,「貓」和「信息」 ķ串... 我已經使用了一些NSlogging弄明白並IGOT是這樣的:
2011-12-19 00:40:07.557 LAO [39912:BC03]:
2011年加工值-12-19 00:40:07.557 LAO [39912:bc03]處理值爲:「某些信息標題...」
2011-12-19 00:40:07.558 LAO [39912:bc03] :
2011-12-19 00:40:07.559 LAO [39912:BC03]處理值:
2011-12-19 00:40:07.560 LAO [39912:bc03]處理值爲:「某些信息標題...」
2011-12-19 00:40:07.560 LAO [39912:bc03]處理值爲:「一些摘要聯繫人在這裏......」 2011-12-19 00:40:07.560 LAO [39912:bc03]摘要 2011-12-19 00:40:07.561 LAO [39912:bc03]處理值用於:
???? 請幫忙
u必須給出的XML是不正確的。你的XML應該有屬性XML或標籤XML。 – mAc 2011-12-19 04:45:16