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 7713545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:54:07+00:00 2026-06-01T01:54:07+00:00

Basically I want to write a class for parsing XML document for my iphone

  • 0

Basically I want to write a class for parsing XML document for my iphone apps.

Here is my header file for the parser which parses a news feed

@interface NewsXML : NSObject<NSXMLParserDelegate>
{
@private
    NSXMLParser *xmlParser;

    NSString *currentElement;
    NSMutableString *currentTitle;
    NSMutableString *currentDate;
    NSMutableString *currentDetail;
    NSMutableString *currentImageURL;
    NSMutableString *currentThumbnailURL;
    NSMutableString *currentAlt;
}

@property (nonatomic, assign) NSObject<NewsXMLDelegate> *delegate;
@property (nonatomic, strong) NSMutableArray *newsItems;
@property (nonatomic, strong) NSURL *url;

- (void)fetch;

@end

There is an array ‘newsItems” which holds the fetched objects from the XML after the method ‘fetch’ is called.

However there are several types of XML files in my program I would like to parse. Each type of XML file have different fields. (Eg : title, date, detail etc)

I create different class (E.g. NewsItem , FooItem , AbcItem ) for holding the Items from different XML files.

I still cannot figure out how to make this XML Parser class to be more general so that the NSMutableArray of items can hold different type of items (NewsItem, FooItem ..) for each case. Now I need to write different XML parser class for each xml file.

So how can this be done in a more general way?

EDIT

Sorry for being unclear.. When the parser parse each item, it will create a new object like ‘NewsItem’, ‘FooItem’ for holding the data and then add it to the array. However, the parser class should not know the existence of these classes (Since more and more item class will be added later). Then how this xml parser class can create the proper objects and add them to the array properly? Is there any way to initialize the parser class with the class of the item?

  • 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-06-01T01:54:09+00:00Added an answer on June 1, 2026 at 1:54 am

    After reading your comment, I don’t think that what you have in mind is a good design for the classes. I think that the XML parser should simply parse XML in a standard way and always return the same thing, and your classes (such as NewsItem, FooItem, etc) should know how to create themselves with the parsed XML. This is much more robust.

    I do this in several apps I’ve made. My NewsItem or FooItem classes implement a function that looks like this:

    - (id)initWithXMLData:(NSDictionary *)xmlDataDictionary {
        self.fooVar = [xmlDataDictionary objectForKey@"xmlParsedKey"];
        //And so on for whatever you need to set from the xml data
    }
    

    This way the XML parsed data is always the same (you dont change the XML parser) and if you need the class to handle the data differently, you change the class’ own initWithXMLData function, instead of changing the XML parser. The XML parser never needs to know about the existence of any other classes.

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

Sidebar

Related Questions

I basically want to write a customer logger/tracer which also logs the class and
I want to write a class which provides basically a list of entries. This
I'm trying to write my first iterator class / container type. Basically, I want
I want to write a rule in prolog, which basically says If a user
I want to write a simple SMPP Server that basically forwards traffic to another
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I want to write a simple class to process Strings (may be very long
So basically i have a backend ORM class which can do all the CRUD
Basicly, I want to write a C++ program and with it, pass messages to
I basically want to be able to deploy multiple versions of the same EAR

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.