Search code examples
iphoneobjective-cxml-parsingnsxmlparsernsxml

Difficulty parsing response containing characters like '\u00'


I am using NSXML Parser to do parsing in my iPhone app. Now everything works fine except when data comes in French language.

For example, data from server comes as Ch\u00e9rie FM.

Now under the string argument of foundCharacters method, I only get string as 'Ch' rest of the characters don't come up. So finally my string is truncated only to 'Ch' intead of the whole Cherie fm

What could be done?

Code:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict
{   
    if (appDelegate.objPlayer.fromFlickrorRecommend == TRUE)
    {
        if([elementName isEqualToString:@"outline"] && [[attributeDict valueForKey:@"text"] isEqualToString:@"You may also like"])
        {
            flagCheck = 1;
        }
        else if ([elementName isEqualToString:@"outline"] && [[attributeDict valueForKey:@"text"] isEqualToString:@"Genres"]) 
        {
            flagCheck = 0;
        }
        if (flagCheck == 1 && [elementName isEqualToString:@"outline"])
        {
            if([[attributeDict valueForKey:@"type"] isEqualToString:@"audio"])
            {
                [appDelegate.objPlayer.recommendDataArray addObject:attributeDict];

            }
        }
    }
    else
    {
        if ([elementName isEqualToString:@"location"])
        {
            flagCheck = 2;
        }
        else if ([elementName isEqualToString:@"url"])
        {   
            flagCheck = 3;
        }
        else if ([elementName isEqualToString:@"name"])
        {   
            flagCheck = 4;
        }
    }   
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{ 
    if (flagCheck == 2)
    {
        flagCheck = -1;
        appDelegate.objPlayer.flickrCity = string;
    }
    else if(flagCheck == 3)
    {
        flagCheck = -1;
        appDelegate.objPlayer.stationURL = string;
    }
    else if(flagCheck == 4)
    {
        flagCheck = -1;
        appDelegate.playStationName = string;
    }
    //else if(flagCheck == 0) // change
//  {
//      appDelegate.playStationName = string;
//  }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{   
    //if (flagCheck == 1 && [elementName isEqualToString:@"outline"])
//  {
//      [appDelegate.objPlayer.recommendDataArray addObject:dataDictionary];
//      dataDictionary = nil;
//      [dataDictionary release];
//  }
}

Solution

  • Got the Answer:

    This link helped while I was going through stackoverflow for the questions similar to my problem.

    Why does arrays handle strings containing swedish ÅÄÖ characters by using two or more indexes?

    Hope this helps all who are looking out for a solution. :)