【发布时间】:2010-12-26 20:41:44
【问题描述】:
这是我的 xml.. 格式。
<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>
我处理了这段代码.....
#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 stringByAppendingString:string];
}
-(void)dealloc{
[currentElementValue release];
[currentElement release];
[super dealloc];
}
@end
当我在控制台中打印时 NSLog(@"数据",appDelegate.cityInfoListArray); 它进行迭代............
示例: 数据
数据 数据
数据 数据 数据 ......
我需要知道这种做解析的方法好不好?????
@提前谢谢............圣诞快乐......新年快乐......向所有的人。
【问题讨论】:
标签: iphone