iphone开发笔记六:gdatexml安装与配置

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:
#import "GDataXMLNode.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 就行了




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值