nicklockwood / XMLDictionary

[DEPRECATED]
http://charcoaldesign.co.uk/source/cocoa#xml-dictionary
Other
1.14k stars 235 forks source link

How to grab XML file on Desktop #54

Closed balistrerin closed 7 years ago

balistrerin commented 7 years ago

Is this how to correctly grab the XML file because it doesn't seem to letting me grab the XML file so I can parse the data?

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"/Users/mycomputer/Desktop/foo" ofType:@"xml"];
NSDictionary *xmlDoc = [NSDictionary dictionaryWithXMLFile:filePath];

if(xmlDoc){
    NSLog(@"Grabbed the doc");
}else{
    NSLog(@"failed to grab the doc");
}

NSString *frame = [xmlDoc valueForKey:@"Frame"];

NSLog(@"Output: %@", frame);
nicklockwood commented 7 years ago

@balistrerin not quite. [[NSBundle mainBundle] pathForResource:] is only for finding files in the application bundle. If you want a file on your desktop, you would just write:

NSString *filePath = @"/Users/mycomputer/Desktop/foo.xml";

The rest is correct.

balistrerin commented 7 years ago

Ah thank you so much. That was it. So I now have another issue where when I:

NSLog(@"Output: %@", frame);

I have 960 frames but it is only printing out the first 87 frames. Is there any reason why that could be happening?

nicklockwood commented 7 years ago

if "frame" is an array, xcode might just be truncating it when it prints. Try:

NSLog(@"frame count %i", frame.count);

nicklockwood commented 7 years ago

If not, it's possible that there is an error in the xml file around node 88 (e.g a missing tag), and so the parser is stopping at that point.

balistrerin commented 7 years ago

Naw it was just truncating. When i did the count i got 960 frames. Thanks for the help man I really appreciate it..epic XMLDictionary.

nicklockwood commented 7 years ago

👍