Click here to Skip to main content
12,356,154 members (66,845 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Mobile iPhone
I am adding data obtained from XML Parser to NSMUtableArray and I see all the values are added except the last value

My XML response is like this:
<List1>
 <CompanyProvider>
    <TimeStart>11:00</TimeStart>
  </CompanyProvider>
  <CompanyProvider>
    <TimeStart>11:15</TimeStart>
 </CompanyProvider>
 <CompanyProvider>
    <TimeStart>11:30</TimeStart>
 </CompanyProvider>
 <CompanyProvider>
    <TimeStart>11:45</TimeStart>
 </CompanyProvider>
<List1>
<CompanyTimeList>
   <CompanyProvider>
     <TimeStart>11:00</TimeStart>
   </CompanyProvider>
 <CompanyProvider>
     <TimeStart>11:15</TimeStart>
   </CompanyProvider>
   <CompanyProvider>
     <TimeStart>11:30</TimeStart>
   </CompanyProvider>
   <CompanyProvider>
     <TimeStart>11:45</TimeStart>
   </CompanyProvider>
</CompanyTimeList>
And I have to consume the value of TimeStart from CompanyTimeList The code I am using is
-(void)ButtonClicked
{
    arr1 = [[NSMutableArray alloc] init];
    drr1 = [[NSMutableDictionary alloc] init];
 
    NSString *urlString = [NSString stringWithFormat:@"http://192.168.0.101:8732/Design_Time_Addresses/IServices/AppointmentService/json/GetAppointments/?cid=999a18dd-50a6-4da0-b692-ef173834435b&pid=aee49598-6199-4f57-90e2-654da651c944&wk=Tuesday&dt=10/16/2012"];    
    NSURL *jsonUrl =[NSURL URLWithString:urlString];
    NSString *jsonStr = [[NSString alloc] initWithContentsOfURL:jsonUrl];  
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:jsonUrl];      
 
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    [parser parse];
    [parser release];
 
    NSLog(@"%@",arr1);      
}
 
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    element = elementName;
 
    if([elementName isEqualToString:@"CompanyTimeList"])
    {
        arr1 = [[NSMutableArray alloc] init];
        drr1 = [[NSMutableDictionary alloc] init];   
    }
 
    if([elementName isEqualToString:@"CompanyProvider"])
    { 
        drr1 = [[NSMutableDictionary alloc] init];        
    }
 
    srr1 = [[NSMutableString alloc] init];
} 
 
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [srr1 appendString:string];
}
 
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if([elementName isEqualToString:@"TimeStart"])
    {    
        [drr1 setObject:srr1 forKey:@"TimeStart"];
        [srr1 release],srr1=nil;
        return;
    }  
 
    if([elementName isEqualToString:@"CompanyProvider"]) 
    { 
        [arr1 addObject:drr1]; 
    }    
 
    if([elementName isEqualToString:@"CompanyTimeList"])
    {      
        [drr1 release];  
    }
 
    [srr1 release], srr1 = nil;
}

\But the response I can see is:
(
    {
        TimeStart="11:00"
    },
    {
        TimeStart="11:15"
    },
    {
        TimeStart="11:30"
    }
    {
        TimeStart=""
    }
)
I can't see the last value, i.e 11:45.Y is missing. Where I am going wrong?
Posted 3-Oct-12 6:26am
cutie1297

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100