I am trying to parse XML file which contains arabic words as follow:
<NewsComponent>
<HeadLine>العلاجية</HeadLine>
</NewsComponent>
when I NSLog the string on the NSXMLParser delegate it prints empty string, and even when i parse the data to the UITableView it shows empty text.
I am encoding the data as UTF-8 before passing it to the parser.
How can I parse the XMl without losing the content of the tag HeadLine?
notes:
1. The same XML with English language is working correctly.
2. Showing the XML in Any browser shows the data correctly.
3. converting the NSData to NSString and NSLog-ing before parsing the NSString show the xml correctly too.
Edit How am I doing this?
NSString *sURLREST = @"http://www.example.com/getXml";
NSURL *url = [NSURL URLWithString:sURLREST];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &error];
NSString* output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData* dataOutput = [output dataUsingEncoding: NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] dataOutput];
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if([sCurrentItem isEqualToString:@"HeadLine"])
{
[mutuableArray addObject:string];
// I am just adding the string value to a NSMutuableArray to bind it with the UITableView.
NSLog(@"%@",string);
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
sCurrentItem = elementName;
}
parser:foundCharacters:method. - Ole Begemann