http://blog.csdn.net/yanwudingkou/article/details/6162896
一开始用的kissxml,但是包引入后老是报一大堆错误(可能是下面的project settings自己没配好)。
后来干脆选择google的xml解析了。gdatexml大概解析速度还可以。
安装:http://code.google.com/p/gdata-objectivec-client/ 上面download
1、一共2个文件。 project 右击添加文件 到项目下面(选中project右击add files to xxx)。第一次导入要选择下面的copy选项复制到文件目录中去
2、点击项目在build settings -》search paths中设置header search paths
3、在linking下面配置other linker flags 为 -lxml2
You can integrate GDataXML into a new project with a few easy steps:
- Choose Project/New Project, and choose View-based Application, and name the project XMLTest.
- Download the gdata-objective-c client library.
- Unzip the file, navigate to Source/XMLSupport, and drag the two files GDataXMLNode.h and GDataXMLNode.m into your project.
- In XCode, click Project/Edit Project Settings and make sure “All Configurations” are checked.
- Find the Search Paths/Header Search Paths setting and add /usr/include/libxml2 to the list.
- Finally, find the Linking/Other Linker Flags section and add -lxml2 to the list.
- Test out that everything is working by adding the following to the top of XMLTestAppDelegate.h:
|
If your app compiles and runs GDataXML is integrated successfully!
// xml
-(void)parseGdatexml:(NSString *) xmlString{
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xmlString options:0 error:nil];
NSArray *items = [doc nodesForXPath:@"//soap:Envelope/soap:Body" error:nil];
for (GDataXMLElement *item in items) {
NSArray *names = [item elementsForName:@"ns1:findAllMenusResponse"];
for(GDataXMLElement *name in names) {
[self parseJsonKit:name.stringValue];
break;
}
}
[doc release];
}
解析例子参考http://www.cocoachina.com/bbs/read.php?tid=82118&page=1
这里赞下楼主,自己解决了问题并且提交了答案,
第一步: 选中文件列表最上方的工程名 然后点TARGETS 里面的工程名 然后点Build Phase
然后点Link Binary With Libraries 然后点下面的加号 搜索 xml 然后添加libxml2.dylib
第二步: 还在工程属性界面 搜索 Header Search Paths 然后添加值 /usr/include/libxml2
第三步:将GDATAXMLNODE.H 和 .m文件添加到工程里
第四步:获得webdata
第五步:假设得到的webdata是这样的
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:webData options:0 error:nil];
NSArray *items = [doc nodesForXPath:@"//Party/Player" error:nil];
for (GDataXMLElement *item in items) {
NSArray *names = [item elementsForName:@"name"];
for(GDataXMLElement *name in names) {
NSLog(@"姓名 %@",name.stringValue) ;
break;
}
NSArray *levels = [item elementsForName:@"level"];
for(GDataXMLElement *level in levels) {
NSLog(@"等级 %@",level.stringValue) ;
break;
}
NSArray *classes = [item elementsForName:@"class"];
for(GDataXMLElement *class in classes) {
NSLog(@"类别 %@",class.stringValue) ;
break;
}
}
后面自己release 就行了