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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:17:41+00:00 2026-05-25T22:17:41+00:00

I would like to look through the elements of a file and when one

  • 0

I would like to look through the elements of a file and when one specific element comes out, output the contents in between the tag.

I tried to follow the example in the Mac Dev entitled Event Driven XML Programming, but it just doesn’t finish very clearly. It says to make sure I code the delegates, but it never shows an example. I just want to see a simple example where:

  • The file is assumed to be a good xml file.
  • Its path is a URL (or string).
  • The way the delegate interacts with the parser is explained.

Many tutorials for Cocoa seem to almost teach you to circumvent the delegate classes and make your own IBAction functions so I’m missing the training I think on how to use the delegates properly. Its not clear in the example if I’m supposed to build the delegates in the delegate class or keep them in the class with the parser.

  • 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-25T22:17:41+00:00Added an answer on May 25, 2026 at 10:17 pm

    This is based on something I originally wrote for Cut out a part of a long NSString. I copied the NSXMLParserDelegate code from that iOS project into an OS X project. It gets the text from a specific object in a web page.

    .h file:

    @interface so7576593AppDelegate : NSObject <NSApplicationDelegate, NSXMLParserDelegate> {
        NSWindow *window;
        IBOutlet NSTextField *textField;
    
        NSMutableString *divCharacters;
        BOOL captureCharacters; 
    }
    
    @property (assign) IBOutlet NSWindow *window;
    
    @end
    

    .m file:

    #import "so7576593AppDelegate.h"
    
    @implementation so7576593AppDelegate
    
    @synthesize window;
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
        captureCharacters = NO;
        NSURL *theURL = [NSURL URLWithString:@"http://maxnerios.yolasite.com/"];
        NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];
        [parser setDelegate:self];
        [parser parse];
        [parser release];
    
    }
    
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
        if ([elementName isEqual:@"div"] && [[attributeDict objectForKey:@"id"] isEqual:@"I3_sys_txt"]) {
            captureCharacters = YES;
            divCharacters = [[NSMutableString alloc] initWithCapacity:500];
        }
    }
    
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
        if (captureCharacters) {
            //from parser:foundCharacters: docs:
            //The parser object may send the delegate several parser:foundCharacters: messages to report the characters of an element. 
            //Because string may be only part of the total character content for the current element, you should append it to the current 
            //accumulation of characters until the element changes.
            [divCharacters appendString:string];
        }
    }
    
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
        if (captureCharacters) {
            captureCharacters = NO;
            [textField setStringValue:divCharacters];
            [divCharacters release];
        }
    }
    
    @end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use javascript to style an element to look like a
I would like to look at some examples of some good form layouts (web-based)
I would like to look up the database table for people whose registered date
I am trying to analyse the IIS log and would like to look at
Im looking to create a control that would look like comic baloon. In WPF
I'm learning iOS development and would really like to look at an example application
In Java, it would look like this: class Foo { float[] array; } Foo
i want to realize a construct in MS SQL that would look like this
How do you create a desktop application using C# that would look like Visual
I am interested in what a SQLite3 database schema would look like for a

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.