NSXML parse image

235 views Asked by At

could somebody help me getting the href attribute from this piece of code? By using NXMLParser.. ThankYou

"<content:encoded><![CDATA[<p><a class="lightbox"  title ="1" href="http://www.enlacejudio.com/wp-content/uploads/2012/05/12.jpg"><img src="http://www.enlacejudio.com/wp-content/uploads/2012/05/12.jpg" alt="" title="1" width="448" height="188" class="aligncenter size-full wp-image-59393" /></a></p>
1

There are 1 answers

6
rishi On BEST ANSWER

considering this as string, you can use like -

NSString *urlString = nil;
NSString *htmlString = //Your string;

NSScanner *scanner = [NSScanner scannerWithString:htmlString];

[scanner scanUpToString:@"href=" intoString:nil];
if (![scanner isAtEnd]) {
    [scanner scanUpToString:@"http" intoString:nil];
    NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@">"];
    [scanner scanUpToCharactersFromSet:charset intoString:&urlString];
}

EDIT -

-(id) loadXMLByURL:(NSString *)urlString { 
    noticias = [[NSMutableArray alloc] init];
    NSURL *url = [NSURL URLWithString:urlString];
    NSData *data = [[NSData alloc] initWithContentsOfURL:url];

    NSStringEncoding encoding;
    NSString *xmlString = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error];
    parser = [[NSXMLParser alloc] initWithData:[xmlString dataUsingEncoding:encoding allowLossyConversion:YES]];
    parser.delegate = self; 
    [parser parse]; 
    return self;
}