NSXMLParser don't get all the tag if the tag have accent
I have a webservice with diferent changes for the DataBase. When I consume the webservice return lines with sql tags, like this:
<sql>
DELETE FROM TABLE WHERE ...
</sql>
<sql>
INSERT INTO TABLE WHERE ...
</sql>
<sql>
UPDATE TABLE SET ... WHERE ...
</sql>
I save this codes in the NSMutableArray like this:
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"sql"]){
[maResultado addObject:[NSMutableString stringWithFormat:@"%@", ResultadoSoap]];
[ResultadoSoap setString:@""];
}
}
This is good, but if the webservice returns a word with an accent (accent because is in spanish), the app only get the phrase after the accent. Example: the web service return this:
<sql>
INSERT INTO DATOS(datos, fecha) VALUES('Indagar si el médico a tenido oportunidad de ...', '20/02/2013')
</sql>
I do this:
if ([elementName isEqualToString:@"sql"]){
[maResultado addObject:[NSMutableString stringWithFormat:@"%@", ResultadoSoap]];
[ResultadoSoap setString:@""];
}
and in the maResultado in the objectatindex only have this:
édico a tenido oportunidad de ...', '20/02/2013')
The parser:foundCharacters:
delegate function can be called more than once for an XML element. This happens in particular if the character content contains special characters. In your case, for the data
<sql>
INSERT INTO DATOS(datos, fecha) VALUES('Indagar si el médico a tenido oportunidad de ...', '20/02/2013')
</sql>
the delegate function is called twice, first with the string
INSERT INTO DATOS(datos, fecha) VALUES('Indagar si el m
and then again with the string
édico a tenido oportunidad de ...', '20/02/2013')
Therefore, you have to append the string in parser:foundCharacters:
to the current string, e.g.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[currentElementValue appendString:string];
}