使用NSData保存來自網頁的XML文件。能不能檢測NSData
中包含<?xml version="1.0"?>
?
NSURL *url = [NSURL URLWithString:link];
NSData *data = [NSData dataWithContentsOfURL:url];
將NSData轉成字符串再判斷是否包含<?xml ...?>
BOOL hasXMLTag=NO;
NSString *findStr=@"<?xml version="1.0"?>";
NSString *xml=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if ([xml hasPrefix:findStr]) {
hasXMLTag=YES;
//to do your logic
}