Reputation: 3543
I have an XML file that looks like this:
<?xml version="1.0"?>
<categories>
<category id="1">
<category_name>Banks</category_name>
</category>
<category id="4">
<category_name>Restaurants</category_name>
</category>
</categories>
The [xmlParser parse] method returns TRUE without errors. But when i print out each element, i get the following results:
Processing characters:
Restaurants
Notice the empty line and slight indent of 'Restaurants'. My foundCharacters method prints out the above.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing characters: %@", currentElementValue);
}
This causes an indentation of the text in my UITableViewCell - why would this be?
The imageView property is not being set.
Thanks Joe
Upvotes: 2
Views: 392
Reputation: 96394
I think what's going on is that whatever the foundCharacters method is writing to isn't getting cleared out on finding the start of a new element, so the whitespace from indenting the tags is still hanging around. If you only clear it when finding the end of an element you would get results like what you describe.
Upvotes: 1
Reputation: 3543
I used the following to solve this problem
NSString *trimmedString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
It worked
Upvotes: 3