如果标记具有重音,则NSXMLParser不会获取所有标记 [英] NSXMLParser don't get all the tag if the tag have accent
问题描述
我有一个Web服务,对DataBase进行了不同的更改。当我使用带有sql标签的webservice返回行时,如下所示:
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>
我将此代码保存在NSMutableArray中,如下所示:
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:@""];
}
}
这很好,但是如果webservice返回一个字带有重音(重音因为是西班牙语),应用程序只在重音后获得短语。
示例:
网络服务返回此信息:
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>
我这样做:
if ([elementName isEqualToString:@"sql"]){
[maResultado addObject:[NSMutableString stringWithFormat:@"%@", ResultadoSoap]];
[ResultadoSoap setString:@""];
}
并且在objectatindex的maResultado中只有这个:
and in the maResultado in the objectatindex only have this:
édico a tenido oportunidad de ...', '20/02/2013')
推荐答案
解析器:foundCharacters:
委托函数可以调用更多而不是一次XML元素。如果字符内容包含特殊字符,则会发生这种情况。在您的情况下,对于数据
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
然后再用字符串
édico a tenido oportunidad de ...', '20/02/2013')
因此,您必须追加字符串在解析器:foundCharacters:
到当前字符串,例如
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];
}
这篇关于如果标记具有重音,则NSXMLParser不会获取所有标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!