开发者

how to parse xml parser with many attributes

This is my xml.. formate.

 <events>
    <event id="237" title="HotFridayz" description="Club home / Amsterdam / N" date="17/12/2010" time="23:00 - 05:00" location="Club Nouvelle" street="Uilenstede 9-3018" city="Amstelveen" visitors="10" organisation="VSSA" price="13" minimum_age="" picture="" genre="Hip Hop" lineup="Dj Wily - Waxfiend" website=""/>
    <event id="238" title="Bassline" description="Jimmy woo/ Amsterdam / Nl" date="17/12/2010" time="23:55 - 03:00" location="P60" street="Katrijpstraat 126" city="Amsterdam" visitors="1000" organisation="first priority" price="15" minimum_age="" picture="" genre="Reggae" lineup="Chucky" website=""/>
    ....
    ....
    ....
    </events>

I worked on this code.....

#import "XMLParser.h"
#import "PartyDemoProjectAppDelegate.h"
#import "CityInfo.h"

@implementation XMLParser
@synthesize currentElementValue;
@synthesize currentElement;

-(XMLParser *)initXMLParser{
    [super init];
    appDelegate = (PartyDemoProjectAppDelegate *)[[UIApplication sharedApplication] delegate];  
    return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict{
    self.currentElement=elementName;
    currentElementValue=@"";
    if ([elementName isEqualToString:@"events"]) {
        appDelegate.cityInfoListArray=[[NSMutableArray alloc]init];

        return;
    }
    if ([elementName isEqualToString:@"event"]) {
    aCityInfo=[[CityInfo alloc] init];
    aCityInfo.event_ID=[attributeDict objectForKey:@"id"];
    aCityInfo.event_Title=[attributeDict objectForKey:@"title"];
    aCityInfo.event_Description=[attributeDict objectForKey=@"description"];
    }
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"events"]) {
    return;
}

    if ([elementName isEqualToString:@"event"]) {
        [appDelegate.cityInfoListArray addObject:aCityInfo];
        [aCityInfo release];
        aCityInfo=nil;
NSLog(@"Data",appDelegate.cityInfoListArray);
    }
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 

//  currentElementValue =  [currentElementValue string开发者_Python百科ByAppendingString:string];
}

-(void)dealloc{

    [currentElementValue release];
    [currentElement release];
    [super dealloc];
}
@end

When i am printing in console NSLog(@"Data",appDelegate.cityInfoListArray); It making iterations..........

example: Data <0X1>

Data <0X1> Data <0X2>

Data <0x1> Data <0x2> Data <0x3> ......

I need to know this approach doing parsing is good?????

@Thanks in advance...........happy xmas... advance new year.. to all the people.


Check out the apple sample code XMLPerformance you may have to login to apple developer account.

I am using same approach, I would suggest to use multi threading to parse data to avoid the pause in the app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜