#import <Foundation/Foundation.h>
@interface FAQIndexOperation : NSOperation{
NSURL *_targetURL;
id _target;
SEL _action;
}
@property(retain) NSURL *targetURL;
@property(retain) id target;
//@property(retain) SEL action;
-(id)initWithURL:(NSURL *)theURL target:(id)theTarget action:(SEL)theAction;
@end
@implementation FAQIndexOperation
@synthesize target,targetURL;
-(id)initWithURL:(NSURL *)theURL target:(id)theTarget action:(SEL)theAction
{
self = [super init];
if(self){
targetURL = [theURL retain];
target = theTarget;
_action = theAction;
}
return self;
}
- (void)dealloc
{
[targetURL release],targetURL=nil;
[target release],target = nil;
[super dealloc];
}
- (void)main
{
CXMLDocument *document = [[CXMLDocumentalloc]initWithContentsOfURL:targetURL encoding:NSUTF8StringEncodingoptions:0 error:nil];
FAQIndexParser *parser = [[FAQIndexParseralloc]initwithDocument:document];
NSMutableArray *faqList = [parser parserFAQIndexPage];
[target performSelectorOnMainThread:_action withObject:faqListwaitUntilDone:YES];
// NSLog(@"done");
[parser release];
}
@end
// FAQIndexParser.h
// Hq88Project
//
// Created by hq88 on 12-9-5.
// Copyright (c) 2012年 hq88.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TouchXML.h"
@interface FAQIndexParser : NSObject
{
CXMLDocument *_document;
NSString *allpage;
// NSMutableArray *_journalList;
}
@property (nonatomic,retain) CXMLDocument *document;
@property (nonatomic,retain) NSString *allpage;
//@property (nonatomic,retain) NSMutableArray *journalList;
-(id)initwithDocument:(CXMLDocument *)document;
-(NSMutableArray *)parserFAQIndexPage;
@end
// FAQIndexParser.m
// Hq88Project
//
// Created by hq88 on 12-9-5.
// Copyright (c) 2012年 hq88.com. All rights reserved.
//
#import "FAQIndexParser.h"
#import "TbFAQ.h"
@implementation FAQIndexParser
@synthesize document;
@synthesize allpage;
//@synthesize journalList = _journalList;
-(NSMutableArray *)parserFAQIndexPage
{
NSMutableArray *faqArray = [[[NSMutableArray alloc]init]autorelease];
NSMutableArray *dataList = [[[NSMutableArray alloc]init]autorelease];
// NSLog(@"********%@",self.document);
CXMLElement *root = [self.document rootElement];
NSArray *items = [root children];
for (CXMLElement *element in items) {
if ([element isKindOfClass:[CXMLElement class]]) {
if ([[element name]isEqualToString:@"courses"]) {
self.allpage = [[element attributeForName:@"allpage"]stringValue];
for (int i = 0; i < [element childCount]; i++) {
if ([[element childAtIndex:i]isKindOfClass:[CXMLElement class]]) {
TbFAQ *faq = [[TbFAQ alloc]init];
CXMLElement *child = [[element children]objectAtIndex:i];
faq.faqID = [[child attributeForName:@"id"]stringValue];
faq.faqName = [[child attributeForName:@"name"]stringValue];
faq.faqGrade = [[child attributeForName:@"grade"]stringValue];
faq.faqImageURL = [[childattributeForName:@"imgurl"]stringValue];
faq.faqLiveURL = [[child attributeForName:@"liveurl"]stringValue];
faq.faqLecturer = [[childattributeForName:@"lecturer"]stringValue];
for (int j = 0; j < [child childCount]; j++) {
if ([[child childAtIndex:j]isKindOfClass:[CXMLElement class]]) {
CXMLElement *summary = [[child children]objectAtIndex:j];
faq.faqSummary = [[summarystringValue]stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];
// NSLog(@"%@",faq.faqSummary);
}
}
[faqArray addObject:faq];
[faq release];
}
}
}
}
}
NSLog(@"self.allpage%@",self.allpage);
[dataList addObject:faqArray];
[dataList addObject:self.allpage];
return dataList;
}
-(id)initwithDocument:(CXMLDocument *)thedocument
{
self = [super init];
if (self) {
document = thedocument;
}
return self;
}
-(void)dealloc
{
[document release],document = nil;
[allpage release],allpage = nil;
// [self.journalList release],self.journalList = nil;
[super dealloc];
}
@end