<?xml version="1.0" encoding="UTF-8"?> <data> <loc> <Title>AS1</Title> <Latitude>1.295182</Latitude> <Longitude>103.771904</Longitude> </loc> <loc> <Title>AS2</Title> <Latitude>1.295171</Latitude> <Longitude>103.771276</Longitude> </loc>
And, I wish to add the content into an object/class (OBJECT NUS) that has title, and Coordinate2d object.
1. In the following code below, I am able to pick up the terms title, latitude and longitude, unfortunately, in the Title part, it never picks up the content of the title (example AS1) Is my code wrong?
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if([elementName isEqualToString:@"loc"]){
self.location=[[NUSLocations alloc]init];
}
if([elementName isEqualToString:@"Title"]){
//NSString* st=[[attributeDict valueForKey:@"Title"]string];
//NSLog(@"%@",st);
}
}
2. However, the following code below, picks up the contents of the stuff, but in a straight order.
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(@"%@",string);
}
3. Then there seems to be another chunk of code I must add, called didEndElement as such, I have no idea what it does
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
Can I know the correct procedure on how to actually parse the above data properly. From what I have read in the tutorial,
didStartElement is for initializing one object, in my case the data between <loc>
parser foundCharacters is to put the contents into the object
and didEndElement is to add the object to the array
I have no idea how to do this, could someone point me in the right direction?

New Topic/Question
Reply


MultiQuote





|