My NSXMLParser breaks on this string:
<title>AAA – BCDEFGQWERTYUIO</title>
I parsed it in this way, hope is the right way:
- (void) parser: (NSXMLParser *) parser foundCharacters: (NSString *) string{
[...]
if ([currentElement isEqualToString:@"title"]) {
if (![string isEqualToString:@""]) {
[title addObject:string];
NSLog(@"str: %@", string);
}
}
it returns me:
str: AAA
str: -
str: BCDEFGQWERTYUIO
But i want to return a single string:
str: AAA - BCDEFGQWERTYUIO
because it's the correct title.
Any idea?
Thanks.
I find that it is better to create your object in the didEndElement method. That way you can just keep appending the string data to some temporary string. So you might do something like below (NOTE: code not tested)
In your object header:
NSMutableString *currentElementData;
...
@property (nonatomic, retain) NSMutableString *currentElementData;
And in your parsing code you would have
- (void) parser: (NSXMLParser *) parser foundCharacters: (NSString *) string{
[...]
if ([currentElement isEqualToString:@"title"]) {
[currentElementData appendString:string];
}
}
Then later in your element did end
- (void) parser: (NSXMLParser *) parser didEndElement: (NSString *) elementName...{
[...]
if ([elementName isEqualToString:@"title"]) {
[title addObject:currentElementData];
[currentElementData setString:@""];
}
}