Chinaunix首页 | 论坛 | 博客
  • 博客访问: 386255
  • 博文数量: 284
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1707
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-14 16:38
文章分类

全部博文(284)

文章存档

2015年(6)

2014年(278)

我的朋友

分类: iOS平台

2014-06-27 14:34:46

1. [代码][C/C++]代码     
NSURL *url = [NSURL URLWithString:
  @""];


NSMutableURLRequest* request = [NSMutableURLRequest new];    


[request setURL:url];    
[request setHTTPMethod:@"GET"]; 


NSHTTPURLResponse* response;    
NSData* data = [NSURLConnection sendSynchronousRequest:request    
returningResponse:&response 
error:nil];   


NSString* responseXMLResult = [[NSString alloc] initWithData:data 


encoding: CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000)];    




NSError *error;


GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString: responseXMLResult


  options:0 error:&error];


if (doc == nil) { return; }


NSLog(@"LOG=%@", [[NSString alloc] initWithData:doc.XMLData encoding:NSUTF8StringEncoding]);


//NSLog(@"%@", doc.rootElement.XMLString);


NSMutableString *resultString = [[NSMutableString alloc] initWithString:@"XML数据内容: \n"];


//NSArray *partyMembers = [doc.rootElement elementsForName:@"Player"];


NSArray *partyMembers = [doc.rootElement nodesForXPath:@"//Party/Player" error:nil];


for (GDataXMLElement *partyMember in partyMembers) {


NSString *_name;
NSString *_level;
NSString *_class;


// Name
//NSArray *names = [partyMember elementsForName:@"Name"];


NSArray *names = [partyMember nodesForXPath:@"Name" error:nil];


if (names.count > 0) {
GDataXMLElement *firstName = (GDataXMLElement *) [names objectAtIndex:0];
_name = firstName.XMLString;
} else continue;




// Level


NSArray *levels = [partyMember elementsForName:@"Level"];


if (levels.count > 0) {
GDataXMLElement *firstLevel = (GDataXMLElement *) [levels objectAtIndex:0];
_level = firstLevel.stringValue;
} else continue;


// Class
NSArray *classes = [partyMember elementsForName:@"Class"];
if (classes.count > 0) {
GDataXMLElement *firstClass = (GDataXMLElement *) [classes objectAtIndex:0];
_class = firstClass.stringValue;


} else continue;


[resultString appendFormat:@"Name=%@",_name ];
[resultString appendFormat:@" Level=%@",_level ];
[resultString appendFormat:@" Class=%@\n",_class ];


}


//textView.text = [[NSString alloc] initWithData:doc.XMLData encoding:NSUTF8StringEncoding];


textView.text = resultString;


    [url release];


[doc release];#SinaEditor_Temp_FontName
阅读(495) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~