0

I am working on XMLParser. I used NSLog and get a following xml string :

<table><tr><td><img src="http://www.24h.com.vn/upload/3-2012/images/2012-09-16/1347762760_bong-da-genoa-juve.jpg"width='80' height='80' /></td><td>(20h, 16/9) Juventus sẽ có trận đấu khó khăn tới sân của Genoa.</td></tr></table>  

how to get link in img src.

I tried:

else if([elementName isEqualToString:@"img"]) 
{ 
    currentString=[attributeDict objectForKey:@"src"]; 
    self.storingCharacter=YES; 
}  

But unsuccessful. Any help?

Himanshu
  • 31,810
  • 31
  • 111
  • 133
  • Please describe "unsuccessful": does the code ever get called? – Sergey Kalinichenko Oct 06 '12 at 11:33
  • 1
    This is a duplicate question. See this post here. It describes exactly what you are looking for http://stackoverflow.com/questions/12147883/parsing-xml-from-nsstring-to-get-values – Sam B Oct 06 '12 at 11:34

1 Answers1

0

You need to implement an html parser to get the objects you wanted. I suggest you to use hpple.

I took the snippet of Albaregar solution from parsing HTML on the iPhone and modified it to your needs. I didn't test the adapted snippet, but it should works.

#import "TFHpple.h"

NSData *data = [[NSData alloc] initWithContentsOfFile:@"yourfile.html"];

// Create parser
xpathParser = [[TFHpple alloc] initWithHTMLData:data];

//Get the first img tag
NSArray *elements  = [xpathParser searchWithXPathQuery:@"//img[0]"];

// Access the first img attribute src
TFHppleElement *element = [elements objectAtIndex:0];

// Get the text within the src attribute
NSString *src_attr = [element content];  

[xpathParser release];
[data release];
Community
  • 1
  • 1
nullpointr
  • 524
  • 4
  • 18