如何使用 NSXMLParser 解析包含&符号的字符串?
输入字符串是
<path>a & b</path>
,我的 Objective C 解析器代码是
- (void) parser:(NSXMLParser *)parser
foundCharacters:(NSString *)string {
...
if(parserState==EXPECT_PATH) {
NSLog(@"got %@", string);
}
...
}
这会打印 got a
而不是 got a & b
The input string is
<path>a & b</path>
and my Objective C parser code is
- (void) parser:(NSXMLParser *)parser
foundCharacters:(NSString *)string {
...
if(parserState==EXPECT_PATH) {
NSLog(@"got %@", string);
}
...
}
This prints got a
instead of got a & b
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
parser:foundCharacters:
可以针对一个元素的内容多次调用。您有责任将该方法的多次运行中的所有字符附加到一个字符串中。因此,除非您可以确认在第一次运行后不会再次调用
parser: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.So unless you can confirm that
parser:foundCharacters:
doesn't get called again right after the first run, this is expected behavior.