How to parse strings containing ampersands with NS

2020-05-05 15:59发布

The input string is

<path>a &amp; 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 &amp; b

1条回答
来,给爷笑一个
2楼-- · 2020-05-05 16:32

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.

查看更多
登录 后发表回答