GDataXMLNode 处理xml


+ (NSString *) xmlOfTest
{
	GDataXMLElement * requestElement = [GDataXMLElement elementWithName:@"root"];
	GDataXMLElement * accountElement = [GDataXMLElement elementWithName:@"account" ];
	//[requestElement addChild:accountElement];//this should be at the last 
	
	[accountElement addAttribute:[GDataXMLNode elementWithName:@"random" stringValue: @"11"]];
	[accountElement addChild:[GDataXMLElement elementWithName:@"mode" stringValue: @"22"]];
	[accountElement addChild:[GDataXMLElement elementWithName:@"reqType" stringValue: @"333"]];
	
	[requestElement addChild:accountElement];
	
	NSString *request = [requestElement XMLString];
	return request;
}

 <root><account random="11"><mode>22</mode><reqType>333</reqType></account></root>

<root><account/></root>


+ (void) getTestDataFromXml:(NSString *)xml
{
	NSError * parseError = nil;
	
	/* 解析XML  */
	// <root><account random="11"><mode>22</mode><reqType>333</reqType></account></root>
	GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xml 
																options:0 error:&parseError];
	
	NSArray *retcodeMembers = [doc.rootElement elementsForName:@"account"];
	if (retcodeMembers.count > 0) 
	{
		GDataXMLElement *retCodeResult = (GDataXMLElement *)[retcodeMembers objectAtIndex:0];
		NSLog(@"%@", [[retCodeResult attributeForName:@"random"] stringValue]);
		
		NSArray * tmpArray = [retCodeResult elementsForName:@"mode"];
		
		NSLog(@"%@", [[tmpArray objectAtIndex:0] stringValue]);
	}
	
	
	[doc release];
}


2012-07-04 16:46:04.277 [96641:10a03] 11
2012-07-04 16:46:23.947 [96641:10a03] 22




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值