NSXMLDocument读取远程XML文件:
NSError *error;
NSURL *url = [NSURL URLWithString:@"http://www.corp.com/info.xml"];
NSString *returnValue = @"";
@try {
NSXMLDocument *doc = [[NSXMLDocument alloc] initWithContentsOfURL:url options:0 error:&error];
NSArray *arrs = [doc nodesForXPath:@"/root/message" error:&error];
returnValue = [[arrs objectAtIndex:0] stringValue];
}
@catch (NSException *exception) {
returnValue = exception.reason;
}
@finally {
//
}
returnValue输出的值应为:test
XML文件格式:
<root>
<message>test</message>
</root>