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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:55:39+00:00 2026-05-27T17:55:39+00:00

I previously asked this question XMLParser Advice . However I am still unable to

  • 0

I previously asked this question XMLParser Advice.

However I am still unable to get it to function properly….

So I guess I will start from scratch:

Located at a certain URL is an XML Tree that looks like this

<result>

   //stuff that I dont need

   <title>
      //thing that I do need
   </title>

  //stuff that I dont need

   <body>
      //thing that I do need
   </body>

<result>

How the heck do I go about parsing that?
The (useless) code I have so far can be found in the link at the top of this question.

Thank you for your time.

  • 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-27T17:55:39+00:00Added an answer on May 27, 2026 at 5:55 pm

    Write a simple class, which will be the parser’s delegate.

    @interface YourObject : NSObject <NSXMLParserDelegate> {
        NSString *title, *body;    // object attributes
        NSXMLParser *parser;       // will parse XML
        NSMutableString *strData;  // will contains string data being parsed
    }
    
    @property(readwrite, copy) NSString *title, body;
    
    // will be used to set your object attributes
    -(void)fetchValuesAtURL:(NSString *)url;
    
    @end
    

    The fetchValuesAtURL: method will initiate the parse operation.

    @implementation YourObject
    
    @synthesize title, body;
    
    -(id)init {
        self = [super init];
        if(self) {
            title = @"";
            body = @"";
            parser = nil;
            strData = [[NSMutableString alloc] initWithCapacity:10];
        }
        return self;
    }
    
    -(void)fetchValuesAtURL:(NSString *)url {
        if(parser) {
            [parser release];
        }
        NSURL *xmlURL = [NSURL URLWithString:url];
        parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
        [parser setDelegate:self];
        [parser parse];
    }
    
    -(void)parser:(NSXMLParser *)parser
     didStartElement:(NSString *)elementName
        namespaceURI:(NSString *)namespaceURI
       qualifiedName:(NSString *)qName
          attributes:(NSDictionary *)attributeDict {
        // element is about to be parsed, clean the mutable string
        [strData setString:@""];
    }
    
    // the probably missing method
    -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
        // content (or part of) has been found, append that to the current string
        [strData appendString:string];
    }
    
    -(void)parser:(NSXMLParser *)parser
       didEndElement:(NSString *)elementName
        namespaceURI:(NSString *)namespaceURI
       qualifiedName:(NSString *)qName {
        // element has been parsed, test the element name
        // and store strData accordingly
        if([elementName isEqualToString:@"title"]) {
            self.title = strData;
        }
        else {    // or else if, here you got two elements to parse
            self.body = strData;
        }
    }
    
    -(void)dealloc {
        [title release];
        [body release];
        [strData release];
        if(parser) {
            [parser release];
        }
        [super dealloc];
    }
    
    @end
    

    Then :

    YourObject *obj = [[YourObject alloc] init];
    [obj fetchValuesAtURL:@"http://www.site.com/xml/url"];
    

    NSXMLParser‘s delegate is able to do many more things, as described in Event-Driven XML Programming Guide from Apple.
    For complete reference on delegate methods, see NSXMLParserDelegate Protocol Reference.

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

Sidebar

Related Questions

This question builds off of a previously asked question: Pass by reference multidimensional array
This is in reference to the question previously asked The problem here is, each
This is an extension of a question I previously asked here . Long story
I asked a similar question about this previously, but I did not specify that
Ok, i've read most relevant questions asked here previously on this but I still
So, I previously asked this question: Can someone help me compare using F# over
Previously I asked this question: Read quicktime movie from servlet in a webpage? Basically
RESOLVED: CSS Animation/Scale issue in Chrome/Webkit I asked this question previously, but I'm not
This question is related to one I asked previously, see here . As a
This question is based on this previously asked question : Magento custom module date

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.