Question

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

Was it helpful?

Solution

I used the following to solve this problem

NSString *trimmedString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

It worked

OTHER TIPS

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.

Is there an ignoreWhiteSpace property you can use?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top