I am trying to use NSScanner is an NSArray enumeration loop. This however fails:
-[NSXMLElement length]: unrecognized selector sent to instance 0x280da30
No, I am not calling length
anywhere. It seems like the value of found gets changed before the scanner completes, hence making it blank, causing the length
error.
If I remove the loop and hardcode the string (i don't want that, it's just a test) the code below works. (excluding the enumeration of course)
It never gets as far as calling the NSLog
s either...
Here's my code:
for (NSString*found in arr)
{
NSLog(@"Found %@",found);
NSString*search = [NSString stringWithString:found];
NSString *separatorString = @"\"";
NSString *container = nil;
NSScanner *aScanner = [NSScanner scannerWithString:search];
[aScanner setScanLocation:0];
[aScanner scanUpToString:@"src=\"" intoString:nil];
[aScanner scanString:@"src=\"" intoString:nil];
[aScanner scanUpToString:separatorString intoString:&container];
NSLog(@"scanned");
NSLog(@"%@",container);
NSImage*previewImage = [[NSImage alloc] initWithContentsOfFile:[relativeDir stringByAppendingPathComponent:container]];
[preview setImage:previewImage];
[previewImage release];
progressed = progressed + 1;
[convertProgress setDoubleValue:[convertProgress doubleValue] + progressed];
}
How can I get this to work?
Edit:
Here's the input:
NSXMLDocument*doc = [[NSXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:webPath] options:NSXMLDocumentTidyHTML error:nil];
NSArray*arr = [doc nodesForXPath:@"//img[@src]" error:nil];