Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:29:05+00:00 2026-06-15T09:29:05+00:00

i have an XML file as url where the file contains like this, <Products>

  • 0

i have an XML file as url where the file contains like this,

<Products>
<products id="1">
<name>product1</name>
<price>$150</price>
<img>http://www.myimage.com/Main_pic.png</img>
</products>
</Products>

Now using NSXMLParser i can retrieve the data and the image but after i get those data am not understanding how to store in NSMutableArray or NSDictionary. Also i tried to implement lazyloading asynchronous image download from Lazy Loading Table Images Asynchronous Downloading from Apple. But i failed to load the images. Do we have any alternative for aynchronous loading.

Kindly describe me in detail about,

  1. how to store a data retieved from url XML file in aysnchronous downloading.
  2. how to separate data and image.
  3. how to implement those in UIImage and data to view in iPhone.

EDITED

for better understanding i need the data and the image like below picture and not in the table view.
Sample Picture

EDITED-2
By using the lazyloading parsing i modified according to my content here the code for your reference,

- (void)main{
self.workingArray = [NSMutableArray array];
self.workingPropertyString = [NSMutableString string];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:dataToParse];
[parser setDelegate:self];
[parser parse];
if (![self isCancelled]){
self.completionHandler(self.workingArray);}
self.workingArray = nil;
self.workingPropertyString = nil;
self.dataToParse = nil;}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"Products"]){
self.workingEntry = [[egsLists alloc] init];}
storingCharacterData = [elementsToParse containsObject:elementName];}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if (self.workingEntry){
if (storingCharacterData){
NSString *trimmedString = [workingPropertyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[workingPropertyString setString:@""];
if ([elementName isEqualToString:sIDStr]){
self.workingEntry.ProductID = trimmedString;}
else if ([elementName isEqualToString:sImageStr]){
self.workingEntry.img = trimmedString;}}
else if ([elementName isEqualToString:@"Products"]){
[self.workingArray addObject:self.workingEntry];
self.workingEntry = nil;}}}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if (storingCharacterData){
[workingPropertyString appendString:string];}}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:29:06+00:00Added an answer on June 15, 2026 at 9:29 am

    take a NSObject Class say DataClass

    // create objects for your data in DataClass.h And Synthesize them in DataClass.m

    - (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];
    
    
    
    }
    

    After That When You Need you can Retrive the Data From Array if you are Using TableView

    then in your CellForRowAtindexPath method use the following:

    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]]];
    

    You can Use LazyTableImages SampleCode from Apple for Loading Images.

    http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

    For Complete XML parsing See the Tutorial or use Below Code:

    Source : http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/

       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]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have an XML file that looks like this: <properties> <property> <picture>http://example.com/image1.jpg</picture> <picture>http://example.com/image2.jpg</picture>
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have this xml file which has text init. i.e Hi my name is
I have some URL that contains special characters. For example: http://www.example.com/bléèàû.html If you type
I have an xml file like this: <?xml version=1.0 ?> <scketchit> <categories> <category title=MANGA
I have an XML file that contains URLs. I want to add cases because
I have this function: http://pastebin.ca/2058418 It basically checks to see if a tables contains
I have a dynamically created xml file that contains a record with five descriptor
I have a flash app that needs to download a file, whose name contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.