Hello helpful community.
Trying to make a very simple application to learn about XML / Parsing, relying on Hillegass and Apple Doc's - just trying to do everything one step at a time.
Have a local XML file (a downloaded RSS Feed), imported to a cocoa project. Have one window program with a button to load the xml file into an NSData object, then another button to use an NSXMLParser Object to parse the data.
The program Crashes as soon as I press the button to Parse XML (see bold code) and my initial Question was 'Why'. Then just before I hit post, I think I got it, and appropriately changed the title of my 'Title.' Questions following the code -
Header:
Relevant Body:
1. thisBundle variable is disappearing, and the pathName which relies on the NSBundle thus ends up pointing to nothing, which is perpetuated - right?
2. OR is it that I am not initializing pathName and xmlData in an init method - in which case, why does the first method not serve that purpose?
3. If the XML file is local (in my resources) - is there an easier way to load it into NSData without using the bundle and string variables at all?
I apologize if this is all very obvious - thanks for any and all help / critique.
Trying to make a very simple application to learn about XML / Parsing, relying on Hillegass and Apple Doc's - just trying to do everything one step at a time.
Have a local XML file (a downloaded RSS Feed), imported to a cocoa project. Have one window program with a button to load the xml file into an NSData object, then another button to use an NSXMLParser Object to parse the data.
The program Crashes as soon as I press the button to Parse XML (see bold code) and my initial Question was 'Why'. Then just before I hit post, I think I got it, and appropriately changed the title of my 'Title.' Questions following the code -
Header:
Code:
@interface GoodNoosAppDelegate : NSObject <NSApplicationDelegate, NSXMLParserDelegate> {
NSWindow *window;
NSData *xmlData;
NSString *pathName;
}
@property (assign) IBOutlet NSWindow *window;
- (IBAction)loadXmlToDataObject:(id)sender;
- (IBAction)parseXml:(id)sender;
Relevant Body:
Code:
- (IBAction)loadXmlToDataObject:(id)sender {
NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
pathName = [thisBundle pathForResource:@"AroundTheDotNet=xml" ofType:@"xml"];
NSLog(@"'pathName' NSString variable contains: %@", pathName);
xmlData = [NSData dataWithContentsOfFile:pathName];
NSLog(@"xmlData NSData object successfully loaded with XML File");
}
- (IBAction)parseXml:(id)sender {
[b]NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];[/b]
NSLog(@"Data Loaded to xmlParser");
/* Other stuff.....*/
}
1. thisBundle variable is disappearing, and the pathName which relies on the NSBundle thus ends up pointing to nothing, which is perpetuated - right?
2. OR is it that I am not initializing pathName and xmlData in an init method - in which case, why does the first method not serve that purpose?
3. If the XML file is local (in my resources) - is there an easier way to load it into NSData without using the bundle and string variables at all?
I apologize if this is all very obvious - thanks for any and all help / critique.