本文介绍了NSXMLParser解析使用Windows-1256编码的xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Windows-1256编码中解析rss文件,但是它没有被解析器
i读取,在UTF8编码中进行了大量的解析,但是这样做不行为什么?
i want to parse rss file in Windows-1256" encoding but it is not being read by parser i done alot of parsing in UTF8 encoding but only this don't work why?
解决
解决方案是
Solved solution is
NSString *myStr = [[NSString alloc] initWithData:myData encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic) ];
myStr = [myStr stringByReplacingOccurrencesOfString:@"encoding=\"windows-1251\"" withString:@""];
NSData* aData = [myStr dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:aData];
推荐答案
谢谢Mohamed的答案,我一直在工作10天,我们没有发现任何答案,这是我的代码:
Thank you Mohamed for the answer I kept working on it for 10 days and we found no answers at all. This is my code:
-(void)parseXMLFileAtURL:(NSString *)URL {
NSURL *xmlURL = [NSURL URLWithString:URL];
NSData * dataXml = [[NSData alloc] initWithContentsOfURL:xmlURL];
NSString *myStr = [[NSString alloc] initWithData:dataXml encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingWindowsArabic)];
myStr = [myStr stringByReplacingOccurrencesOfString:@"encoding=\"windows-1256\"" withString:@""];
NSData *aData = [myStr dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *rssParser = [[NSXMLParser alloc] initWithData:aData];
[dataXml release];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
[rssParser setDelegate:nil];
[rssParser release];
}
这篇关于NSXMLParser解析使用Windows-1256编码的xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!