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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:06:54+00:00 2026-05-20T16:06:54+00:00

I’m a newbie to Cocoa, just develop some little apps with C/C++ on Windows.

  • 0

I’m a newbie to Cocoa, just develop some little apps with C/C++ on Windows.
I want to make a “simple” app on Cocoa.
When the user specific XML file, the file nodes are represented “enduser viewable”.

I made an interface with some NSTextField.
I made a subclass of NSDocument called “XMLFile” so I got “XMLFile.h” and “XMLFile.m” in my Xcode project.

In the plist of my app I set up a new “Document Types”:
XML File – extensions: xml – role: view – class: XMLFile – store type: XML

Here is my “XMLFile.h”:

#import <Cocoa/Cocoa.h>


@interface FichierXML : NSDocument {

}

        IBOutlet NSTextField *dateField;
        IBOutlet NSTextField *titleField;
        IBOutlet NSTextField *descField;
        IBOutlet NSTextField *vidfileField;
        IBOutlet NSTextField *imgfileField;
        IBOutlet NSObjectController *object;
        NSUInteger *mask;

@end

And here is my “XMLFile.m”:

#import "XMLFile.h"

@implementation XMLFile

- (BOOL)readFromData:(NSData *)datafile ofType:(NSString *)typeName error:(NSError **)outerror

{

    NSMutableArray* ReportCreationDate = [[NSMutableArray alloc] initWithCapacity:10];
    NSMutableArray* ReportTitle = [[NSMutableArray alloc] initWithCapacity:10];
    NSMutableArray* ReportDescription = [[NSMutableArray alloc] initWithCapacity:10];
    NSMutableArray* VideoPath = [[NSMutableArray alloc] initWithCapacity:10];
    NSMutableArray* VideoThumbnailImageName = [[NSMutableArray alloc] initWithCapacity:10];

    NSXMLDocument* doc = [[NSXMLDocument alloc] initWithData:datafile options:mask error:outerror];
    NSXMLElement* root  = [doc rootElement];
    NSArray* dateElement = [root nodesForXPath:@"//Report/ReportCreationDate" error:nil];
    for(NSXMLElement* xmlElement in dateElement)
        [dateElement setStringValue:[xmlElement stringValue]];
    NSArray* titleElement = [root nodesForXPath:@"//Report/ReportTitle" error:nil];
    for(NSXMLElement* xmlElement in titleElement)
        [titleField setStringValue:[xmlElement stringValue]];
    NSArray* descElement = [root nodesForXPath:@"//Report/ReportDescription" error:nil];
    for(NSXMLElement* xmlElement in descElement)
        [descField setStringValue:[xmlElement stringValue]];
    NSArray* vidfileElement = [root nodesForXPath:@"//Report/Videos/Video/VideoPath" error:nil];
    for(NSXMLElement* xmlElement in vidfileElement)
        [vidfileField setStringValue:[xmlElement stringValue]];
    NSArray* imgfileElement = [root nodesForXPath:@"//Report/Videos/Video/VideoThumbnailImageName" error:nil];
    for(NSXMLElement* xmlElement in imgfileElement)
        [imgfileField setStringValue:[xmlElement stringValue]];

    [doc release];
    [ReportCreationDate release];
    [ReportTitle release];
    [ReportDescription release];
    [VideoPath release];
    [VideoThumbnailImageName release];

    return YES;
}

@end

The user opens the XMLFile, and XMLDocument analyses the file to extract nodes’ data and sends it to the differents NSTextField. But it doesn’t work.

If someone can help me.

  • 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-20T16:06:54+00:00Added an answer on May 20, 2026 at 4:06 pm

    You’re not too specific about what doesn’t work, but here’s a guess or two at some things that could be causing trouble…

    One thing that can be easy to forget as a new Cocoa user is that IBOutlets have to be actually hooked up in Interface Builder. Control-drag from each text field to File’s Owner in your Document.xib, and make sure that they are assigned to the correct outlet.

    Another item that seems strange (though I don’t know for sure it would cause a problem) is your use of a for loop to set the stringValue of the text fields. If there is more than one item in each element’s array, you will need to concatenate the strings yourself before setting the text field’s value. Repeatedly setting the value will simply get rid of the previous value. If there is only one item in each array, why not simply do:

    NSArray *dateElement = [root 
                   nodesForXPath:@"//Report/ReportCreationDate" 
                           error:nil];
    [dateField setStringValue:
               [[dateElement objectAtIndex:0] stringValue]];
    

    Finally, you might want to try making sure there are no errors when you’re querying the NSXMLDocument:

    NSError *dateErr;
    NSArray *dateElement = [root 
                   nodesForXPath:@"//Report/ReportCreationDate" 
                           error:&dateErr];
    if( dateElement ){
        // set the stringValue
    }
    else {
        // inspect the error
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.