[英]IOS Encoding ISO-8859-9
I need to get contents of an XML file which is hosted on web, and parse it. 我需要获取Web上托管的XML文件的内容,并对其进行解析。
I decided to use TouchXML for parsing process. 我决定使用TouchXML进行解析。 However, I cannot get contents of the file since it is encoded with ISO-8859-9
但是,我无法获取文件的内容,因为它是使用ISO-8859-9编码的
XML File Url: http://rss.haberler.com/mobil/sondakika2.asp?kategori=manset XML档案网址: http : //rss.haberler.com/mobil/sondakika2.asp? kategori = manset
I have tried 2 different approachs. 我尝试了2种不同的方法。
1) Getting contents of url into NSString: 1)获取url的内容到NSString中:
NSString *url = @"http://rss.haberler.com/mobil/sondakika2.asp?kategori=manset";
NSError *error = nil;
NSStringEncoding encoding;
NSString *xmlString = [[NSString alloc] initWithContentsOfURL: [NSURL URLWithString:url] usedEncoding:&encoding error:&error];
xmlString becomes null, and error description says: xmlString变为null,并且错误描述如下:
The operation couldn’t be completed. (Cocoa error 261.)
Instead of usedEncoding, I also tried specifying encoding explicitly, from UTF-8 to NSISOLatin1StringEncoding and NSISOLatin2StringEncoding (unfortunately, I could not find NSISOLatin9StringEncoding). 我还尝试使用UTF-8到NSISOLatin1StringEncoding和NSISOLatin2StringEncoding显式指定编码,而不是usedEncoding(不幸的是,我找不到NSISOLatin9StringEncoding)。
2) I also tried to load xml into NSData. 2)我也试图将xml加载到NSData中。
NSError *error = nil;
NSData *XMLData = nil;
XMLData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:url] options:0 error:&error];
When I constructed XML Parser, specific characters are unknown and application terminates when I get string values. 当我构造XML解析器时,特定字符是未知的,当我得到字符串值时,应用程序终止。
CXMLDocument *doc = [[CXMLDocument alloc] initWithData:XMLData options:0 error:nil];
NSArray *nodes = [doc nodesForXPath:@"//item" error:nil];
for (CXMLElement *node in nodes) {
for(int counter = 0; counter < [xmlElement childCount]; counter++) {
CXMLNode * child = [xmlElement childAtIndex:counter];
NSString *childName = child.name;
NSString * childValue = [child stringValue];
}
}
Getting stringValue of child terminates application with SIGABRT. 获取子级的stringValue会使用SIGABRT终止应用程序。
How can I fix the problem? 我该如何解决该问题?
From the TouchXML CXMLDocument.m
file, this is what initWithData:
looks like 在TouchXML
CXMLDocument.m
文件中,这就是initWithData:
- (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError
{
return [self initWithData:inData encoding:NSUTF8StringEncoding options:inOptions error:outError];
}
What you could try doing is, in this file, replace NSUTF8StringEncoding
with NSASCIIStringEncoding
or whatever encoding it uses. 您可以尝试在此文件中用
NSASCIIStringEncoding
或它使用的任何编码替换NSUTF8StringEncoding
。 That may fix it. 那可能会解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.