Reputation: 160
I am facing problem in converting the Spanish text that is fetched from the service in
correct format. Server side they are encoding with ISO-8859-1
. It is a xml service. In my
iOS7 app, I am using TBXml
parser to parse the data. The code is:
NSString *XMLString = [[NSString alloc] initWithContentsOfURL:urlString encoding:NSISOLatin1StringEncoding error:nil];
TBXML *tbxml = [[TBXML alloc] initWithXMLString:XMLString];
I am parsing this data, but the when there are Spanish characters like "BEBÉS Y" the my
string will be "BEB…S Y" . And "øPor quÈ albergamos a alborotadores?" instead of "¿Por qué albergamos a alborotadores?" . Please help
Upvotes: 0
Views: 234
Reputation: 130132
You should download the XML data as binary (NSData
) and let the parser handle the encoding.
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error;
TBXML *tbxml = [TBXML tbxmlWithXMLData:data error:&error];
Note the XML should have the content encoding as the first line so there is no need to specify an encoding in code.
Upvotes: 1
Reputation: 2369
Try with NSUTF8StringEncoding
NSString *XMLString = [[NSString alloc] initWithContentsOfURL:urlString encoding:NSUTF8StringEncoding error:nil];
TBXML *tbxml = [[TBXML alloc] initWithXMLString:XMLString];
UPDATE:
NSData *dataContent = [[NSData dataWithContentsOfURL:urlString];
NSString *XMLString = [[NSString alloc] initWithData:dataContent encoding:NSISOLatin1StringEncoding];
TBXML *tbxml = [[TBXML alloc] initWithXMLString:XMLString];
UPDATE 2: Try with data initialization
NSData *dataContent = [[NSData dataWithContentsOfURL:urlString];
TBXML *tbxml = [[TBXML alloc] initWithXMLData:XMLString];
Upvotes: 0