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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:05:50+00:00 2026-05-12T00:05:50+00:00

Today I am looking into how to make a simple XML parser in Cocoa

  • 0

Today I am looking into how to make a simple XML parser in Cocoa (for the desktop). I am thinking of using NSXMLParser to parse the data, but am not quite sure where to start. The XML file on the web doesn’t have the much data in it, just a simple listing with a few things that I need to save into a variable. Does anyone have any suggestions on how to do this, as the online documentation about this isn’t making too much sense.

Thanks for any help!

EDIT The reason why I am wanting to create an XML parser is to get information from a MYSQL database on a server to the client application. If there is some better way to do this besides a XML parser, please let me know!

  • 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-12T00:05:50+00:00Added an answer on May 12, 2026 at 12:05 am

    Here’s how it works:

    There’s a class called NSXMLParser. It’s used to parse XML files. However, NSXMLParser is stupid. All it knows how to do is parse XML, but it doesn’t know what it’s supposed to do with the information it finds.

    Enter a delegate. A delegate is like a nanny. Since the XMLParser doesn’t have a clue what to do with the information it finds, it goes and asks its delegate about each and every thing: “Hey! I started parsing a document! Am I supposed to do anything?” “Hey! I found some CDATA! What am I supposed to do with it!” “Hey! I found another tag!” “Hey! I found a closing tag!”, and so on. All of these “Hey!” statements are delegate methods, or in other words, they are optional methods that a delegate object may choose to implement. Usually (but not always), the object that creates the NSXMLParser is also the delegate, but that doesn’t have to be the case.

    So you might have something like this:

    NSXMLParser * parser = [[NSXMLParser alloc] initWithContentsOfURL:someURLToAnXMLFile];
    [parser setDelegate:self];
    [parser parse];
    [parser release];
    

    Then in that same object (self), you might have some of these methods:

    - (void)parserDidStartDocument:(NSXMLParser *)parser {
      //the parser started this document. what are you going to do?
    }
    
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
      //the parser found an XML tag and is giving you some information about it
      //what are you going to do?
    }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
      //the parser found some characters inbetween an opening and closing tag
      //what are you going to do?
    }
    
    - (void)parserDidEndDocument:(NSXMLParser *)parser {
      //the parser finished. what are you going to do?
    }
    

    There are a whole bunch of these methods listed in the documentation. Simply go to the NSXMLParser class reference, and they’re all listed under the “Delegate Methods” section. Once you get the hang of it, NSXMLParser is pretty easy to use. It is a SAX Parser, which means it’s event-driven parser. It finds stuff, and it tells you about it.

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

Sidebar

Related Questions

Today, I ran into this weird problem with a user using Mac OS X.
I'm looking into using Umbraco for my site and so far I'm loving it.
Today I was looking at some code atually from Nikhil Kothari's Facebook.NET API. I
I'm been a PHP developer for quite some time now but until today I've
I am just started out learning Python and also started looking into Django a
We're looking at patterns such as MVP that can help make us seperate UI
I'm looking for a Git alternatives to svn info. Today I added some information
I'm looking for pointers and information here, I'll make this CW since I suspect
Still beavering away, slowly sorting out how things work. Today I've been looking at
I'm looking at using fullCalendar and using qTip to display a description using eventMouseover.

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.