views:

203

answers:

0

I am trying to parse the XML located at this URL: http://www.iglooseat.com/gis_iphone_xml.php?zip=06488

1) This method gets invoked when the user presses a button on the Iphone to retrieve the xml data

(IBAction)getLocations:(id)sender {
 ...

 NSString *urlString= [[NSString alloc]
        initWithFormat:@"http://www.iglooseat.com/gis_iphone_xml.php?zip=%@"
                      ,zipField.text];
 ...
}

2) This method takes the URL and performs XML parsing on the data at that URL.

(void)updateLocationsFromURL:(NSString *)urlString parseError:(NSError **)error{

     NSURL *url = [[NSURL alloc] initWithString:urlString];

     NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];

     errorConnecting = NO;

     [url release];

     [parser setDelegate:self];

     [parser setShouldProcessNamespaces:YES];

     [parser setShouldReportNamespacePrefixes:NO];

     [parser setShouldResolveExternalEntities:NO];

     // start the event-driven parsing operation
     [parser parse];

     // get NSError object if an error occured during parsing
     NSError *parseError = [parser parserError];
     if(parseError && error) {
      *error = parseError;
      NSLog(@"Error code:%d %@", parseError.code, parseError.domain);
      errorConnecting = YES;
     }

     // relase from mem the parser
     [parser release];
    }

3) In the parser:didStartElement:namespaceURI:qualifiedName:attributes: I attempt to extract the 'state' attribute from a 'marker' element in my xml. When I use the gdb debugger to inspect the contents of attributeDict it is empty and I'm not sure why.

    (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
                  namespaceURI:(NSString *)namespaceURI 
                    qualifiedName:(NSString *)qName 
                  attributes:(NSDictionary *)attributeDict {

         if(self.parserContentOfCurrentProperty == nil) {
          NSMutableString *tmp = [[NSMutableString alloc] init];
          self.parserContentOfCurrentProperty = tmp;
          [tmp release];
         } 
       [self.parserContentOfCurrentProperty setString:@""];

       self.parserNameOfCurrentProperty = elementName;
       if ([elementName isEqualToString:@"markers"]) {
        WPSite *tmp = [WPSite alloc];
        self.parserCurrentSite = tmp;

        // retrive value for attribute <marker ... state="value" .../></markers>
        NSString *stateAttribute = [attributeDict valueForKey:@"state"];
        if (stateAttribute) {
         [self.parserCurrentSite setState:stateAttribute];
        }


  // add this site to the site list
  [siteList addObject:self.parserCurrentSite];
  return;
 }
}