I’m parsing this line:
<type>branch</type>
with this code in didEndElement
if ([elementName isEqualToString:@"type"]) {
[currentBranchDictionary setValue:currentText forKey:currentElementName];
}
When I test the value in the type key, it does not contain branch but instead it contains branch\n. Here is the test I’m performing:
if ([[currentBranchDictionary valueForKey:@"type"] isEqualToString:@"branch"]) {
NSLog(@"no new-line");
} else if ([[currentBranchDictionary valueForKey:@"type"] isEqualToString:@"branch\n"]) {
NSLog(@"new-line");
}
this returns the “new-line” output
Here’s the foundCharacters method:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
[currentText appendString:string];
}
I don’t understand where the carriage return is being added, can anyone help?
I suspect your XML contains carriage returns (“\r”) that aren’t being displayed by your editor. The XML specification requires these to be translated to line feeds (“\n”) prior to reporting the result to your application:
http://www.w3.org/TR/REC-xml/#sec-line-ends
Can you verify the contents of your XML file? What is the output from the xxd command? Here’s the output from a file I created. Note the extra 0d character: