Hey All,
Im writing an application in which i need to grab data from an xml file (which i get by sending data to a url). Just so everyone gets it ill describe my process:
1. I get the location of the user (for this experiment, im using a static URL, in the real deal i would be using lat and long i get from my location manager)
2. I input my formatted URL into a string, using
3. I then init my url using the string i just made using
4. I then init my XMLParser using
4b. This the XML i get back (or should be getting back from the URL Request)
5. That then goes to the XML Parser i made which im attaching so people can actually help
6. I then try to print the name i get out of my xml file into a labels text field using
(where name is the entity within the XML file that houses my location name)
Using the debugger my breakdown right now is occurring when the parser goes through the didStartElement function in number 5. The
Any help would be appreciated,
ive posted alot of my code on here, and while im not a senior "amazing" developer I would like to ask that my code be used only for educational purposes and even though my code is pretty generic dont copy and paste for your own gain, your only hurting yourself by not learning how to code.
Thats my little disclaimer, any help would be awesome, thanks again, if you need any other part of my code please tell me and im sure i can work something out.
Thanks,
Daniel
Im writing an application in which i need to grab data from an xml file (which i get by sending data to a url). Just so everyone gets it ill describe my process:
1. I get the location of the user (for this experiment, im using a static URL, in the real deal i would be using lat and long i get from my location manager)
2. I input my formatted URL into a string, using
Code:
NSString *string = @"myurl";
Code:
NSURL *url = [NSURL URLWithString:string];
Code:
locationFeed = [[[iPhoneLocation alloc] initWithURL:url] retain];
Code:
−<geonames>
−<geoname>
<name>Laguna Woods</name>
<lat>33.6103009</lat>
<lng>-117.7253305</lng>
<geonameId>5364369</geonameId>
<countryCode>US</countryCode>
<countryName>United States</countryName>
<fcl>P</fcl>
<fcode>PPL</fcode>
<distance>0.8177</distance>
−</geoname>
−</geonames>
Code:
- (iPhoneLocation*) initWithURL:(NSURL*)url
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
items = [[NSMutableArray alloc] init];
currentProperty = nil;
curItem = nil;
curCategory = nil;
[parser parse];
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"geonames"]) {
curItem = [[NSMutableDictionary alloc] init];
}
else if(curItem != nil) {
currentProperty = [[[NSString alloc] initWithString:elementName] retain];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if(curItem != nil && [elementName isEqualToString:@"geonames"]) {
[items addObject:curItem];
[curItem release];
curItem = nil;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(curItem != nil && currentProperty != nil) {
[curItem setObject:string forKey:currentProperty];
[currentProperty release];
currentProperty = nil;
}
}
- (NSArray*)items {
return items;
}
6. I then try to print the name i get out of my xml file into a labels text field using
Code:
myLocationLabel.text = [[[locationFeed items] objectAtIndex:1] objectForKey:@"name"];
Using the debugger my breakdown right now is occurring when the parser goes through the didStartElement function in number 5. The
Any help would be appreciated,
ive posted alot of my code on here, and while im not a senior "amazing" developer I would like to ask that my code be used only for educational purposes and even though my code is pretty generic dont copy and paste for your own gain, your only hurting yourself by not learning how to code.
Thats my little disclaimer, any help would be awesome, thanks again, if you need any other part of my code please tell me and im sure i can work something out.
Thanks,
Daniel