three 20 解析 xml

前端之家收集整理的这篇文章主要介绍了three 20 解析 xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//

// CMBCMallMessageEngine.h

//

//

// Created by on 1/31/13.

// Copyright (c) 2013 P&C,PhoneYeah. All rights reserved.

//


#import<Foundation/Foundation.h>





@interface CMBCMallMessageEngine :NSObject <TTURLRequestDelegate>

{

TTURLRequest *_mallMessageDownLoadRequest;

TTURLRequest *_mallMessageUpDateRequest;

}

@property (nonatomic,retain)TTURLRequest *mallMessageDownLoadRequest;

@property (nonatomic,retain)TTURLRequest *mallMessageUpDateRequest;



-(void)cancleRequest;

-(void)sendDownLoadMallMessageRequest;

-(void)cancleDownLoadRequest;

-(void)sendUpDateMessageRequest;

-(void)cancleUpDateRequest;


@end


//

// CMBCMallMessageEngine.m

//

//

// Created by on 1/31/13.

// Copyright (c) 2013 P&C,PhoneYeah. All rights reserved.

//


#import"CMBCMallMessageEngine.h"

#import"CMBCMallPromptMessage.h"


@implementation CMBCMallMessageEngine

@synthesize mallMessageDownLoadRequest =_mallMessageDownLoadRequest;

@synthesize mallMessageUpDateRequest =_mallMessageUpDateRequest;


-(void)dealloc

{

[_mallMessageDownLoadRequestrelease];

[_mallMessageUpDateRequestrelease];

[superdealloc];

}


-(void)cancleRequest

{

[selfcancleDownLoadRequest];

[selfcancleUpDateRequest];

}


-(void)sendDownLoadMallMessageRequest

{

self.mallMessageDownLoadRequest = [TTURLRequestrequestWithURL:CMBC_DOWNLOAD_MESSAGE_URLdelegate:self];

[self.mallMessageDownLoadRequestsetHttpMethod:Request_HttpMethod_Get];

[self.mallMessageDownLoadRequestsetContentType:@"appliction/xml"];

TTURLXMLResponse *response = [[TTURLXMLResponsealloc]init];

self.mallMessageDownLoadRequest.response = response;

response.isRSSFeed =YES;//导致 xml root 只有一个

[response release];

[self.mallMessageDownLoadRequestsend];

}


-(void)cancleDownLoadRequest

{

if (_mallMessageDownLoadRequest && [_mallMessageDownLoadRequestisLoading])

{

[_mallMessageDownLoadRequestcancel];

}

}


-(void)sendUpDateMessageRequest

{


}


-(void)cancleUpDateRequest

{

if (_mallMessageUpDateRequest && [_mallMessageUpDateRequestisLoading])

{

[_mallMessageUpDateRequestcancel];

}

}


-(void)parserXMLResponse:(TTURLXMLResponse *)response

{

TTURLXMLResponse *mallmessageResponse = (TTURLXMLResponse *)response;

NSDictionary *mallmessageRoot = mallmessageResponse.rootObject;

NSDictionary *messagelist = [mallmessageRoot objectForKey:@"mesgLists"];

NSDictionary *messagel = [messagelist objectForKey:@"mesgList"];

NSArray *messagearray = [messagel objectForKey:@"mesg"];

//NSInteger arraycount = messagearray.count;

CMBCMallPromptMessage *mallPromptmessage = [[CMBCMallPromptMessagealloc]init];


for (id item in messagearray) {

NSString * messageId = [[item objectForKey:@"busiId"]objectForXMLNode];

// NSString *messageId = @"1001";

NSString *message = [[item objectForKey:@"busiText"]objectForXMLNode];

if ([messageId isEqualToString:@"1001"]) {

mallPromptmessage.cinemaTicketMessage = message;

}

else if([messageId isEqualToString:@"1002"])

{

mallPromptmessage.gameCardMessage = message;

}

else if([messageId isEqualToString:@"1003"])

{

mallPromptmessage.passengerTicketMessage = message;

}

else if([messageId isEqualToString:@"1004"])

{

mallPromptmessage.interMarketmessage = message;

}

}



[CMBCMallPromptMessagesaveMallPromptMessageToUserDefault:mallPromptmessage];

}


#pragma TTURLRequest delegate回调


-(void)request:(TTURLRequest *)request didFailLoadWithError:(NSError *)error

{


}


-(void)requestDidFinishLoad:(TTURLRequest *)request

{

if (request ==self.mallMessageDownLoadRequest) {

if ([request.response isKindOfClass:[TTURLXMLResponse class]]) {

//parserXML

[selfparserXMLResponse:request.response];

}

}

elseif (request ==self.mallMessageUpDateRequest)

{

}


}


@end


注释: response.isRSSFeed=YES;//导致xml root只有一个
不设置 isRSSFeed 会导致 xml 解析失败 只有一个root
原文链接:https://www.f2er.com/xml/298755.html

猜你在找的XML相关文章