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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:12:38+00:00 2026-05-15T09:12:38+00:00

I was wondering how do I use the NSXML parser. so lets say given

  • 0

I was wondering how do I use the NSXML parser.
so lets say given I have a simple xml file with elements like:

<Today>
<Date>1/1/1000</Date>
<Time>14:15:16</Time>
</Today>

How could I use the NSXMLParser to parse the XML File (It’s on locally btw, desktop), check through each element and store each of them in an array either to be displayed/used later?

I was looking through some documentation about it and I have no idea on how to use the parser
I know that there are 3 methods (or more, please correct me if I’m wrong) that can be overridden
-..etc didStartElement
-..etc didEndElement
-..etc foundCharacters

  • 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-15T09:12:39+00:00Added an answer on May 15, 2026 at 9:12 am

    The simplest thing is to do something like this:

    NSXMLParser *xmlParser = [[NSXMLParser alloc]initWithData:<yourNSData>];
    [xmlParser setDelegate:self];
    [xmlParser parse];
    

    Notice that setDelegate: is setting the delegate to ‘self’, meaning the current object. So, in that object you need to implement the delegate methods you mention in the question.

    so further down in your code, paste in:

        - (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
            namespaceURI:(NSString *)namespaceURI
           qualifiedName:(NSString *)qualifiedName 
             attributes:(NSDictionary *)attributeDict{
    
           NSLog(@"I just found a start tag for %@",elementName);
           if ([elementName isEqualToString:@"employee"]){
           // then the parser has just seen an <employee> opening tag
           }         
         }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    NSLog(@"the parser just found this text in a tag:%@",string);
    }
    

    etc. etc.

    It’s a little harder when you want to do something like set a variable to the value of some tag, but generally it’s done using a class variable caleld something like “BOOL inEmployeeTag” which you set to true (YES) in the didStartElement: method and false in the didEndElement: method – and then check for it’s value in the foundCharacters method. If it’s yes, then you assign the var to the value of string, and if not you don’t.

    richard

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

Sidebar

Related Questions

I am wondering when to use static methods? Say if I have a class
I'm wondering how to use functions from another script in Lua. For example, say
I am wondering how to use apply on a multidimensional array. I have something
I was wondering how to use GCC on my C source file to dump
i was wondering when we use the init method in a project? i have
So I have 0.5MB XML file with data for my iPhone application. It's all
I was wondering how to use array_push to multidimensional arrays? I have a multidimensional
I'm wondering whether to use CoreData or simple sqlite database for an iOS app.
I am wondering how to use generate command to do something like this: rails
I am wondering how to use the linq retrieving an XML which looks exactly

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.