有人可以帮我从这段代码中获取href属性吗? 通过使用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>
答案 0 :(得分:0)
将此视为字符串,您可以使用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];
}
编辑 -
-(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;
}