KissXML类库的使用方法
1、添加附件里面的KissXML到工程
2、加入libxml2.dylib 到Frameworks
3、修改工程信息,右击Targets下工程名选“Get Info”,进入修改Header Search Paths值为:/usr/include/libxml2,如附件图
附件2为Demo,可运行。
NSString *content = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding error:&error]; [string release]; [self parsedDataFromString:content]; } -(void)parsedDataFromString:(NSString *)str{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:str options:0 error:nil]; /////解析 NSArray *items = [doc nodesForXPath:kXML error:nil]; for (DDXMLElement *obj in items) { xmlData *data = [[xmlData alloc] init]; DDXMLElement *aUser = [obj elementForName:KUSER]; if(aUser) data.user = aUser.stringValue; DDXMLElement *aTitle = [obj elementForName:KTITLE]; if(aTitle) data.title = aTitle.stringValue; DDXMLElement *content = [obj elementForName:KCONTENT]; if(content) data.content = content.stringValue; NSDictionary *XmlDictionary; XmlDictionary = [NSDictionary dictionaryWithObjectsAndKeys: data.user,@"kUsers", data.title,@"kTitles", data.content,@"kContents", nil]; [self performSelectorInBackground:@selector(parsedXml:) withObject:XmlDictionary]; [data release]; } [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [doc release]; }