Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6787485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:22:18+00:00 2026-05-26T17:22:18+00:00

I’m parsing flight times in my iPhone app. Here’s a snippet from the XML

  • 0

I’m parsing flight times in my iPhone app.

Here’s a snippet from the XML

<?xml version="1.0" encoding="iso-8859-1"?>
<airport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<flights lastUpdate="2011-11-07T10:49:43">
<flight uniqueID="2131560">
  <airline>DY</airline>
  <flight_id>DY1052</flight_id>
  <dom_int>S</dom_int>
  <schedule_time>2011-11-04T06:00:00</schedule_time>
  <arr_dep>D</arr_dep>
  <airport>SVG</airport>
  <via_airport>CPH</via_airport>
  <check_in>C</check_in>
</flight>
<flight uniqueID="2136807">
  <airline>SK</airline>
  <flight_id>SK308</flight_id>
  <dom_int>D</dom_int>
  <schedule_time>2011-11-07T07:15:00</schedule_time>
  <arr_dep>D</arr_dep>
  <airport>SVG</airport>
  <via_airport>SVG</via_airport>
  <check_in>EF</check_in>
</flight>
...

I store each flight in a Flight object which looks like this:

@interface Flights : NSObject{
NSInteger flightUniqueID;
NSString *airline;
NSString *flight_id;
NSString *dom_int;
NSDate *schedule_time;
NSString *arr_dep;
NSString *airport;
NSString *check_in;
NSString *status;
NSString *via_airport;
NSString *gate;
NSString *delayed;

}
@property(nonatomic, readwrite)NSInteger flightUniqueID;
@property(nonatomic, retain)NSString *airline;
@property(nonatomic, retain)NSString *flight_id;
@property(nonatomic, retain)NSString *dom_int;
@property(nonatomic, retain)NSDate *schedule_time; 
@property(nonatomic, retain)NSString *arr_dep;
@property(nonatomic, retain)NSString *airport;
@property(nonatomic, retain)NSString *check_in;
@property(nonatomic, retain)NSString *status;
@property(nonatomic, retain)NSString *via_airport;
@property(nonatomic, retain)NSString *gate;
@property(nonatomic, retain)NSString *delayed;

I use an NSXMLParser to parse the XML

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

if ([elementName isEqualToString:@"airport"]) {
    allFlights = [[NSMutableArray alloc]init];
}
else if([elementName isEqualToString:@"flight"]){
    flight = [[Flights alloc]init];

    flight.flightUniqueID = [[attributeDict objectForKey:@"uniqueID"]integerValue];

}

}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { 
  if(!currentElementValue) 
    currentElementValue = [[NSMutableString alloc] initWithString:string];
else
    [currentElementValue appendString:string];


}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

if ([elementName isEqualToString:@"flights"]) {
    return;
}
if ([elementName isEqualToString:@"flight"]) {
    NSLog(@"Adding object: %@" , flight);
    [allFlights addObject:flight];

    [flight release];
    flight = nil;
}else
    [flight setValue:currentElementValue forKey:elementName];

   [currentElementValue release];
currentElementValue = nil;
}

When i NSLog “flight”, I get this output:

Adding object: <Flights: 0xsomenumber>
...
Adding object: <Flights: 0x7064360>

which goes on for however many flights there are in the xml.

However, the array I add each object to only stores the last flight object. If I try to NSLog the array after the parsing is done, it prints out the last object, and nothing else.

Obviously I need to have all the flights stored in the array, so I can show all of them in my tableview after the parsing is done.

How can I achieve this? Am I missing something?

I tried to parse the XML without releasing the flight object, but that didn’t work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:22:19+00:00Added an answer on May 26, 2026 at 5:22 pm

    You set allFlights to an empty array upon airport elements. My guess is that you want to initialize it once upon start.

    However, there are nested airport elements in each flight element, so you end up only with the last flight. Try initializing allFlights somewhere else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.