如何使用NSXMLParser解析包含&符号的字符串? [英] How to parse strings containing ampersands with NSXMLParser?
本文介绍了如何使用NSXMLParser解析包含&符号的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入字符串是
<path>a & b</path>
我的Objective C解析器代码是
and my Objective C parser code is
- (void) parser:(NSXMLParser *)parser
foundCharacters:(NSString *)string {
...
if(parserState==EXPECT_PATH) {
NSLog(@"got %@", string);
}
...
}
这打印得到
而不是得到了& amp; amp; b
推荐答案
解析器:foundCharacters:
可以多次调用一个元素的内容。您有责任将方法的多次运行中的所有字符附加到一个字符串。
parser:foundCharacters:
can be called multiple times for one element's contents. It is your responsibility to append all characters from multiple runs of the method to one string.
所以除非你能确认解析器:foundCharacters:
在第一次运行后没有再次调用,这是预期的行为。
So unless you can confirm that parser:foundCharacters:
doesn't get called again right after the first run, this is expected behavior.
这篇关于如何使用NSXMLParser解析包含&符号的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文