ISO-8859-1 analysis with NSXmlParser

I am using nsxmlparser and wondering how to parse ISO-8859-1 in NSString correctly.

I am currently getting w / Â results for double-byte characters.

The XML I use (not created by me) starts with <?xml version="1.0" encoding="ISO-8859-1"?>

Here are the main calls I use (missed NSThread calls).

NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:sampleFileName ofType:@"xml"];

NSString *xmlFileContents = [NSString stringWithContentsOfFile:xmlFilePath encoding:NSUTF8StringEncoding error:nil];

NSData *data = [xmlFileContents dataUsingEncoding:NSUTF8StringEncoding];

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];

[parser setDelegate:self];

[parser parse];
+3
source share
2 answers

The XML specification recommends explicit character encoding declarations in document prologs. Your input document probably has one; which will tell you the encoding that the parser should use to interpret character input.

, UTF-8 UTF-16 ( , ).

, XML , , , Doing It Wrong ™ , XML.

+3

, , ISO-8859-1, ( ), , UTF-8. " utf-8", , UTF-8, UTF-8. , UTF-8, . UTF-8, , (, UTF-8, ).

, , XML HTTP-, HTTP.

, , XML . , feedparser (Python) XML-XML ( , ).

0

Source: https://habr.com/ru/post/1737865/


All Articles