The project contains two folders within its root directory:
To use KissXML within your project, there are two steps:
The KissXML folder contains:
After adding the KissXML folder you'll need to add libxml2 to your Xcode project. There are 2 steps to this process:
You'll be adding this to your compiler instructions (at project level, not target level)
The latest versions of KissXML use ARC. If you're not using ARC in your project, learn how to properly flag the KissXML files as ARC in your Xcode project on the ARC page.
转载:https://github.com/robbiehanson/KissXML/wiki/GettingStarted
写一个解析XML数据的简单Demo(以KissXml为例) (在iOS代码库中浏览本帖)
1、添加附件里面的KissXML到工程
2、加入libxml2.dylib 到Frameworks 3、修改工程信息,右击Targets下工程名选“Get Info”,进入修改Header Search Paths值为:/usr/include/libxml2,如附件图 附件2为Demo,可运行。 PS:本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]; } |
附件:
KissXML.zip (23 K) 下载次数:1828
附件:
parserDataWithKissXml.zip (48 K) 下载次数:2348
|
转载:http://www.cocoachina.com/bbs/read.php?tid=44701