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?
with every loop you create a new array:
instead you want a NSMutableArray outside of the llop and add an object during every loop
if the increasing array is confusing for you, you should put the NSLog after the for loop: