Since foundCharacters
can be called multiple times per content of a tag, this is incorrect:
-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)strin{
if (isTag) {
rValue =strin;
}
}
Rather than assigning strin
to rValue
, you should be appending it. Currently, the actual value (say, @"BusinessName"
) gets recognized and assigned, but then the @"\n\n\n"
continuation string comes along inside the same tag, and gets assigned on top of the value that has been found first.
Make rValue
an NSMutableString
, and use appendString
, like this:
-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)strin{
if (isTag) {
[rValue appendString:strin];
}
}
Note that the content wold have \n
s at the end as well. If you do not need these trailing characters, you would need to remove them manually, for example, by calling stringByTrimmingCharactersInSet:
, and passing it [NSCharacterSet whitespaceAndNewlineCharacterSet]
as the parameter:
NSString *finalValue = [rValue stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]
];