开发者

Get substring from xml string objective-c

I know this question has been asked many times. I've response string that contains xml.

开发者_开发技巧<?xml version="1.0" encoding="utf-8"?>
<response>116363111</response>

For each request i receive new short xml string, and i need to get value in "response" node. How i can do this, without creating xml parser? I don't want to create xml parser for this short xml.


You could use NSScanner and scan from <response> up to </response>.

NSString *xmlString = @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response>116363111</response>";

NSString *startTag = @"<response>";
NSString *endTag = @"</response>";
NSString *responseString;

NSScanner *scanner = [[NSScanner alloc] initWithString:xmlString];
[scanner scanUpToString:startTag intoString:nil];
scanner.scanLocation += [startTag length];
[scanner scanUpToString:endTag intoString:&responseString];
[scanner release];

NSLog(@"Response string is %@", responseString);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜