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 7979795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:52:15+00:00 2026-06-04T09:52:15+00:00

I am attempting to parse an XML and store the URL from one element

  • 0

I am attempting to parse an XML and store the URL from one element of the XML into an NSArray. Here is my code so far:

 NSURL *url = [NSURL URLWithString:@"http://www.316apps.com/LakesideDocs/podcasttrial.xml"];

   NSData *xmlData = [[NSMutableData alloc] initWithContentsOfURL:url];
   NSError *error;
   GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData 
                                                          options:0 error:&error];

   NSArray *channels = [doc.rootElement elementsForName:@"channel"];
   for (GDataXMLElement *channel in channels) {            


       NSArray *items = [channel elementsForName:@"item"];
       for (GDataXMLElement *item in items) {

           NSString *articlePoint = [item valueForChild:@"link"];
           NSArray *linkarray = [[NSArray alloc] initWithObjects:articlePoint, nil];

           NSLog(@"%@", linkarray);

       }

   }

For the NSLog I would expect:

TabBarSample[40191:fb03] (
    (
    "http://domain.com/image1.jpg"
 ),
(
"http://domain.com/image2.jpg"
)
)

But I get:

TabBarSample[40191:fb03] (
"http://domain.com/image1.jpg"
)
TabBarSample[40191:fb03] (
"http://domain.com/image2.jpg"
)

What am I doing wrong?

  • 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-04T09:52:17+00:00Added an answer on June 4, 2026 at 9:52 am

    with every loop you create a new array:

     NSArray *linkarray = [[NSArray alloc] initWithObjects:articlePoint, nil];
    

    instead you want a NSMutableArray outside of the llop and add an object during every loop

       NSMutableArray *linkarray = [NSMutableArray array];
       NSArray *items = [channel elementsForName:@"item"];
       for (GDataXMLElement *item in items) {
    
           NSString *articlePoint = [item valueForChild:@"link"];
           [linkarray addObject:articlePoint];
    
           NSLog(@"%@", linkarray);
    
       }
    

    if the increasing array is confusing for you, you should put the NSLog after the for loop:

       NSMutableArray *linkarray = [NSMutableArray array];
       NSArray *items = [channel elementsForName:@"item"];
       for (GDataXMLElement *item in items) {
    
           NSString *articlePoint = [item valueForChild:@"link"];
           [linkarray addObject:articlePoint];
       }
    
       NSLog(@"%@", linkarray);
       NSLog(@"count: %d", [linkarray count]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to parse some JSON from a URL via Flash/AS3. Here's my
I am attempting to parse a XML file using Javascript and I'm running into
I'm attempting to parse XML in the following format (from the European Central Bank
I'm attempting to parse load a rather complicated XML schema into a Schema object
I'm attempting to parse an XML file, and generate & insert the element data
I am attempting to insert a parsed XML element into the middle of a
So I've managed to get the feed from twitter and am attempting to parse
I am attempting to parse an XML file using python expat. I have the
I am attempting to parse the incoming JSON from XBMC (Eden Beta v3), an
I am attempting to parse keydown events from the numberpad with the following: $('#myDiv').keydown(function(e)

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.