Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>take a <code>NSObject</code> Class say <code>DataClass</code> </p> <p>// create objects for your data in <code>DataClass.h</code> And <code>Synthesize</code> them in <code>DataClass.m</code> </p> <pre><code>- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { DataClass *mydata=[[DataClass alloc]init]; if ([elementName isEqualToString:@"id"]) { mydata.idvalue=[currentNodeContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } if ([elementName isEqualToString:@"name"]) { mydata.namevalue=[currentNodeContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } if ([elementName isEqualToString:@"price"]) { mydata.pricevalue=[currentNodeContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } if ([elementName isEqualToString:@"img"]) { mydata.imgLink=[currentNodeContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } [myArray addObject:mydata]; } </code></pre> <p>After That When You Need you can Retrive the Data From Array if you are Using <code>TableView</code></p> <p>then in your <code>CellForRowAtindexPath</code> method use the following:</p> <pre><code>DataClass *mydata=[[DataClass alloc]init]; mydata=[myarray objectAtindex:indexPath.row]; cell.textlabel.text=mydata.nameValue; cell.imageView.image=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:mydata.imglink]]]; </code></pre> <p>You can Use <a href="http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html" rel="nofollow">LazyTableImages SampleCode</a> from Apple for Loading Images.</p> <p><a href="http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html" rel="nofollow">http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html</a></p> <p>For Complete XML parsing <a href="http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/" rel="nofollow">See the Tutorial</a> or use Below Code:</p> <p>Source : <a href="http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/" rel="nofollow">http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/</a></p> <pre><code> NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://opentestdrive.com/Products.xml"]]; // Perform request and get JSON as a NSData object NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] ; NSLog(@"responseString=%@", responseString); NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:url]]; [request setHTTPMethod:@"GET"]; NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (conn) { receivedData = [[NSMutableData data] retain]; } else { } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [receivedData appendData:data]; } - (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementname isEqualToString:@"imgName"]) { //if you Taking any NSObject Class then Alloc init here. } } - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementname isEqualToString:@"name"]) { namelable.text=currentNodeContent; } if ([elementname isEqualToString:@"price"]) { pricelabel.text = currentNodeContent; } if ([elementname isEqualToString:@"imgName"]) { imageView.image=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:currentNodeContent]]]; } } - (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload