I'm using NSXMLParse to parse my file.xml. It does work, but when I extract the inside text this file.xml, some words are cutted and I suppose that is an encoding problem.
For example, a little part of my file.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<book>
<titulo>Síndrome de Tietê</titulo>
<pagina numero="1">
<linha numero="1">A luz forte do sol lá fora fazia um grande contraste com o escuro do cômodo.</linha>
<linha numero="2">Poucas pessoas. Móveis rústicos e panelas penduradas, com teias de aranha. Gente magra.</linha>
</pagina>
</book>
So, when I parse and extract the '', the content is: 'á fora fazia um grande contraste com o escuro do cômodo'
INSTEAD OF 'A luz forte do sol lá fora fazia um grande contraste com o escuro do cômodo'
I don't know why, but it's cutting the phrase when appears such word 'á'. It's happening with all tags, always that there's something inside like this 'á,ó,ô,é...'
For this reason, I'm wondering if have to do with 'enconding' from my XML file.
My code for load my XML file:
-(id)loadXMLByURL:(NSString *)fileName:(NSString *)extName {
NSString *xml开发者_如何学CFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extName];
NSData *xmlData = [NSData dataWithContentsOfFile:xmlFilePath];
xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
xmlParser.delegate = self;
[xmlParser parse];
return self;
}
Calling above function:
xmlCon = [[XMLControl alloc] loadXMLByURL:@"geracao":@"xml"];
Any ideas?
The first thing to check is whether the encoding declared at the top of the XML file is actually what the file is encoded in. The old-fashioned way to check is to look at the output of a hex dump or octal dump and verify that characters like í are represented by the expected two-byte sequence. The easier way to check is look at the file in an editor that understands the concept of character encodings (almost any programming editor) and see what encoding it says the file is in. If it doesn't match the declaration, XML parsers will misinterpret the file.
精彩评论