Thursday, October 22, 2009

XML Reader (3)

This is third post in a series (others here and here). If you're following along at home, you'll need the code for main.m. This app is built from the command line---no Xcode. We pass in a file name and read it using NSUserDefaults. No error checking---now that'll put hair on your chest!

Just make sure that you have a file called article.xml on your Desktop, and that it's formatted correctly.

// gcc -o test test.m Reader.m -framework Foundation -fobjc-gc-only
// ./test -ifile article.xml
#import <Foundation/Foundation.h>
#import "Reader.h";

int main (int argc, const char * argv[]) {
NSUserDefaults *args = [NSUserDefaults
NSString *fn =
[args stringForKey:@"ifile"];
[NSURL fileURLWithPath:fn];

Reader *R = [[[Reader alloc] init] retain];
[R read:xmlURL];

//[R reportAll];
NSMutableDictionary *mD = [R processEntries];
NSLog(@"final version %@", mD);

fn = NSHomeDirectory();
fn = [fn stringByAppendingString:
NSURL *fu;
fu = [NSURL fileURLWithPath:fn];
NSLog(@"write %@", fu);
[mD writeToURL:fu atomically:YES];
return 0;

No comments: