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

  • Home
  • SEARCH
  • 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 5947141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:55:21+00:00 2026-05-22T16:55:21+00:00

I have an application where I am using nsxmlparser to parse XML. But I

  • 0

I have an application where I am using nsxmlparser to parse XML. But I don’t have the XML file. I have an API method which produces the XML file. I have produced the xml file in console. But the problem is I don’t know how to parse the API method. I have written the following code, but it does not produce the output.

TWeatherElement.h

//This is my element class .
#import <Foundation/Foundation.h>

@interface TWeatherElement : NSObject
{
    NSString *mIcon;
    NSString *mCurrentdate;
    NSString *mConditionname;
    NSString *mMintemp;
    NSString *mMaxtemp;
    NSString *mWind;
    NSString *mHumidity;
}

@property (nonatomic,retain) NSString *icon;
@property (nonatomic, retain)NSString *currentdate;
@property (nonatomic,retain)NSString *conditionname;
@property (nonatomic,retain)NSString *mintemp;
@property (nonatomic, retain)NSString *maxtemp;
@property (nonatomic, retain)NSString *wind;
@property (nonatomic, retain)NSString *humidity;

@end

TWeatherElement.m

#import "TWeatherElement.h"

@implementation TWeatherElement
@synthesize icon = mIcon;
@synthesize currentdate = mCurrentdate;
@synthesize conditionname = mConditionname;
@synthesize mintemp = mMintemp;
@synthesize maxtemp = mMaxtemp;
@synthesize wind = mWind;
@synthesize humidity = mHumidity;

-(void)dealloc
{
    [mIcon release];
    //[mForecastdate release];
    [mCurrentdate release];
    [mConditionname release];
    [mMintemp release];
    [mMaxtemp release];
    [mWind release];
    [mHumidity release];
    [super dealloc];
}

@end

TWeatherParser.h

//TWeatherParser is my parser class
#import "TWeatherElement.h"
#import <Foundation/Foundation.h>

@interface TWeatherParser : NSObject<NSXMLParserDelegate>
{
    NSMutableArray *mParserArray;
    NSXMLParser *mXmlParser;
    NSMutableString *mCurrentElement;
    BOOL elementFound;
    TWeatherElement *mWeather;
}
@property (nonatomic, retain) NSMutableString *currentElement;
@property (nonatomic, retain) TWeatherElement *weatherobj;

-(void)getInitialiseWithData:(NSData *)inData;

@end

TWeatherParser.m

#import "TWeatherParser.h"
#import "JourneyAppDelegate.h"
//#define kParsingFinishedNotification @"ParsingFinishedNotification"

@implementation TWeatherParser
@synthesize weatherobj = mWeatherobj;
@synthesize currentElement = mCurrentElement;

-(void)getInitialiseWithData:(NSData *)inData
{
    mWeather = [[TWeather alloc]init];
    [mParserArray removeAllObjects];
    NSBundle* bundle = [NSBundle mainBundle];

    //This is to get to the path of the xml file named contact_data, but
    //my problem is I don't have an XML file. My XML file is generated
    //through an API method, [(NSString *)getBusXMLAtStop:(NSString*)stopnumber]

    What should I write here so that I can parse my XML file which
    is retrieving through the above below API method?

}

API METHOD:
-(NSString *)getBusXMLAtStop:(NSString*)stopnumber
{
    NSError *error;
    NSURLResponse *response;
    NSData *dataReply;
    NSString *stringReply;

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
                                    [NSURL URLWithString: [NSString stringWithFormat:@"http://www.google.com/ig/api?weather=,,,50500000,30500000",stopnumber]]];
    [request setHTTPMethod: @"GET"];
    dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    //NSString *str;
    stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
    NSLog(@"%@",stringReply);
    return stringReply;
}

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString*) elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString*)qualifiedName attribute:(NSDictionary*)attributeDict
{
    if (nil!= qualifiedName)
    {
        elementName = qualifiedName;
    }
    if ([elementName isEqualToString:@"weather"])
    {
        self.weatherobj = [[TWeatherElement alloc]init];
    }
    else if([elementName isEqualToString:@"current_date_time data"]||
            [elementName isEqualToString:@"condition data"]||
            [elementName isEqualToString:@"humidity data"]||
            [elementName isEqualToString:@"icon data"]||
            [elementName isEqualToString:@"wind_condition data"]||
            [elementName isEqualToString:@"low data"]||
            [elementName isEqualToString:@"high data"])
    {
        self.currentElement = [NSMutableString string];
    }
    else
    {
        self.currentElement = nil;
    }
}

-(void)parser:(NSXMLParser*)parser foundCharacters:(NSString*)string
{
    if (nil!= self.currentElement)
    {
        [self.currentElement appendString:string];
    }
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName
{
    if (nil != qName)
    {
        elementName  = qName;
    }
    if ([elementName isEqualToString:@"current_date_time data"])
    {
        self.weatherobj.currentdate = self.currentElement;

    }
    else if ([elementName isEqualToString:@"condition data"])
    {
        self.weatherobj.conditionname = self.currentElement;

    }
    else if ([elementName isEqualToString:@"humidity data"])
    {
        self.weatherobj.humidity = self.currentElement;

    }
    else if ([elementName isEqualToString:@"icon data"])
    {
        self.weatherobj.icon = self.currentElement;

    }
    else if ([elementName isEqualToString:@"wind_condition data"])
    {
        self.weatherobj.wind = self.currentElement;

    }
    else if ([elementName isEqualToString:@"low data"])
    {
        self.weatherobj.mintemp = self.currentElement;

    }
    else if ([elementName isEqualToString:@"high data"])
    {
        self.weatherobj.maxtemp = self.currentElement;

    }

    else if ([elementName isEqualToString:@"weather"])
    {
        [mParserArray addObject:self.weatherobj];
        NSLog(@"mDataArray count = %d",[mParserArray count]);
        [self.weatherobj release];
    }
}

-(void)dealloc
{
    self.weatherobj = nil;
    self.currentElement = nil;
    [super dealloc];
}
@end

How to call the API method in the getInitialiseWithData function so that I can parse my XML file?

  • 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-22T16:55:22+00:00Added an answer on May 22, 2026 at 4:55 pm

    Get the string containing the XML from the API and pass the string (it must have a function that takes the string).

    Or just turn the string into NSData,

    NSData* data=[stringContainingXML dataUsingEncoding:NSUTF8StringEncoding];
    

    You need to use a parser library, libxml, touchxml, or NSXMLparser. Look on Google, and do a simple tutorial. After that you should have no problem.
    I suggest touchxml. I never used it, but I hear it’s easy to use compared to the rest.

    Good luck mate.

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

Sidebar

Related Questions

I have application using Android 2.1 which utilize LocationManager to get the altitude. But
I have a control application - using asp.net webservices. I have a timer which
I'm certainly no Ruby developer but I have an application on my server using
I have the application using an .ico image for the taskbar and window, but
Scenario I have an application using asp.net Master Pages in which I would like
So I have 0.5MB XML file with data for my iPhone application. It's all
I have an application using POE which has about 10 sessions doing various tasks.
I am create on application for weathercondition by nsxmlparser using. I have created three
I have an application using JSF, which has a navigation bug. The homepage, which
I have a basecamp account which I'm trying to access via its XML API.

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.