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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:57+00:00 2026-05-27T10:24:57+00:00

today I want to try parsing an xml data from an URL. I use

  • 0

today I want to try parsing an xml data from an URL. I use NSXMLParser to get xml data an process it on my app. Now, the problem is when I try to log the result, I just got one item parsed. Is there any step that I missed..?

What I want is try to get all items on this xml. But, why I only get one item parsed..??? Could anyone help me..?

xml data.

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <generator>Feed Generator</generator>
        <title>Title</title>
        <link>http://m.example.com/index.html</link>
        <description>semua description tentang situs ini</description>
        <language>id-ID</language>
        <pubDate>Thu, 08 Dec 2011 18:00:51 +0700</pubDate>
        <lastBuildDate>Thu, 08 Dec 2011 18:00:51 +0700</lastBuildDate>
        <webMaster>me@me.me (Editor)</webMaster>
        <image>
            <title>Image Title/title>
            <url>http://imagelink.com/image.jpg</url>
            <link>http://imagelink.com/imageindex.html</link>
        </image>

        <item>
            <title><![CDATA[Article Title]]></title>
            <link>http://article-example.com</link>
            <pubDate>Thu, 08 Dec 2011 17:23:00 +0700</pubDate>
            <dc:creator>example.com</dc:creator>
            <category><![CDATA[]]></category>
            <guid isPermaLink="false">0000380840</guid>
            <description><![CDATA[article description]]></description>
            <content:encoded><![CDATA[article content]]></content:encoded>
            <enclosure url="http://imageurl.com/image.jpg" length="10240" type="image/jpg"/>
        </item>

        <item>
            <title><![CDATA[Article Title]]></title>
            <link>http://article-example.com</link>
            <pubDate>Thu, 08 Dec 2011 17:23:00 +0700</pubDate>
            <dc:creator>example.com</dc:creator>
            <category><![CDATA[]]></category>
            <guid isPermaLink="false">0000380840</guid>
            <description><![CDATA[article description]]></description>
            <content:encoded><![CDATA[article content]]></content:encoded>
            <enclosure url="http://imageurl.com/image.jpg" length="10240" type="image/jpg"/>
        </item>

        <item>
            <title><![CDATA[Article Title]]></title>
            <link>http://article-example.com</link>
            <pubDate>Thu, 08 Dec 2011 17:23:00 +0700</pubDate>
            <dc:creator>example.com</dc:creator>
            <category><![CDATA[]]></category>
            <guid isPermaLink="false">0000380840</guid>
            <description><![CDATA[article description]]></description>
            <content:encoded><![CDATA[article content]]></content:encoded>
            <enclosure url="http://imageurl.com/image.jpg" length="10240" type="image/jpg"/>
        </item>
    </channel>
</rss>

Here is my code.

file .h

    NSXMLParser *rssParser;
    NSMutableArray *articles;
    NSMutableDictionary *item;
    NSMutableString *currentElement;
    NSData *xmlFile;


    NSMutableString *elementValue, *feedTitle, *feedDate, *feedDesc, *feedID, *feedEnclosure, *feedContent, *feedLink;

    BOOL errorParsing;

.

file .m
/////////XML PARSE/////////////
- (void)parseXMLFileAtURL:(NSString *)URL{
    NSString *agentString = @"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1";
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]];
    [request setValue:agentString forHTTPHeaderField:@"User-Agent"];
    xmlFile = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    articles = [[NSMutableArray alloc] init];
    errorParsing=NO;

    rssParser = [[NSXMLParser alloc] initWithData:xmlFile];
    [rssParser setDelegate:self];

    [rssParser setShouldProcessNamespaces:NO];
    [rssParser setShouldReportNamespacePrefixes:NO];
    [rssParser setShouldResolveExternalEntities:YES];

    [rssParser parse];
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
    NSString *errorString = [NSString stringWithFormat:@"Error code %i", [parseError code]];
    NSLog(@"Error parsing XML: %@", errorString);
    NSLog(@"Check your internet connection: %@", errorString);

    errorParsing=YES;
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    elementValue = [elementName copy];
    if ([elementName isEqualToString:@"item"]) {
        item = [[NSMutableDictionary alloc] init];
        feedTitle = [[NSMutableString alloc] init];
        feedDate = [[NSMutableString alloc] init];
        feedContent = [[NSMutableString alloc] init];
        feedLink = [[NSMutableString alloc] init];
        feedDesc = [[NSMutableString alloc] init];
        feedID = [[NSMutableString alloc] init];
        feedEnclosure = [[NSMutableString alloc] init];
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    if ([elementValue isEqualToString:@"title"]) {
        [feedTitle appendString:string];
    }else if ([elementValue isEqualToString:@"link"]){
        [feedLink appendString:string];
    }else if ([elementValue isEqualToString:@"content:encoded"]){
        [feedContent appendString:string];
    }else if ([elementValue isEqualToString:@"pubDate"]){
        [feedDate appendString:string];
    }else if ([elementValue isEqualToString:@"guid"]){
        [feedID appendString:string];
    }else if ([elementValue isEqualToString:@"enclosure"]){
        [feedEnclosure appendString:string];
    }else if ([elementValue isEqualToString:@"description"]){
        [feedDesc appendString:string];
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    if ([elementName isEqualToString:@"item"]) {

        [item setObject:feedTitle forKey:@"title"];
        [item setObject:feedLink forKey:@"link"];
        [item setObject:feedDate forKey:@"pubDate"];
        [item setObject:feedContent forKey:@"content:encoded"];
        [item setObject:feedDesc forKey:@"description"];
        [item setObject:feedEnclosure forKey:@"enclosure"];
        [item setObject:feedID forKey:@"guid"];
        [articles addObject:item];
    }
}

- (void)parserDidEndDocument:(NSXMLParser *)parser{
    if (errorParsing == NO) {

        NSLog(@"ID:%@", feedID);
        NSLog(@"title:%@", feedTitle);
        NSLog(@"date created: %@", feedDate);
        NSLog(@"%@", feedEnclosure);
        NSLog(@"%@", feedContent);

        NSLog(@"XML processing done!");
    }else{
        NSLog(@"error processing xml file");
    }
}
////////////////////////////////

.

the result

2011-12-08 18:51:18.305 FlipView[1537:f803] ID:0000380840

2011-12-08 18:51:18.306 FlipView[1537:f803] title:Article Title

2011-12-08 18:51:18.307 FlipView[1537:f803] date created: Mon, 08 Dec 2011 17:23:00 +0700

2011-12-08 18:51:18.307 FlipView[1537:f803] 



2011-12-08 18:51:18.308 FlipView[1537:f803] article content

2011-12-08 18:51:18.308 FlipView[1537:f803] XML processing done!
  • 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-05-27T10:24:58+00:00Added an answer on May 27, 2026 at 10:24 am

    This is because parserDidEndDocument is called only once at the end of parsing. You intend to run this code at the end of each item.

    EDIT: Sorry thought this was implied. Change your code to this.

    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
        if ([elementName isEqualToString:@"item"]) {
    
            [item setObject:feedTitle forKey:@"title"];
            [item setObject:feedLink forKey:@"link"];
            [item setObject:feedDate forKey:@"pubDate"];
            [item setObject:feedContent forKey:@"content:encoded"];
            [item setObject:feedDesc forKey:@"description"];
            [item setObject:feedEnclosure forKey:@"enclosure"];
            [item setObject:feedID forKey:@"guid"];
            [articles addObject:item];
    
            NSLog(@"ID:%@", feedID);
            NSLog(@"title:%@", feedTitle);
            NSLog(@"date created: %@", feedDate);
            NSLog(@"%@", feedEnclosure);
            NSLog(@"%@", feedContent);
    
           }
    }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select data between 1 week ago data until today data: SELECT
Today my new HP iPAQ was delivered at my home, but now I want
wget is helpful in my data mining projects. Today I try to wget the
I want to resolve a status 405 that I get from the task queue
I want to get date range between from and till in Rails seed. When
today i've bumped in the following problem. I have the following xml: <c:docschema xmlns:c=http://www.otr.ru/sufd/document/desc
Today I needed to parse some data out from an xlsx file (Office open
Today I try to rewrite some ugly url in order to be cache by
I've been trying for days now to try and sort this out. Today was
I have a text e.g text<- i am happy today :):) I want to

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.