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

  • Home
  • SEARCH
  • 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 8460741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:41:29+00:00 2026-06-10T13:41:29+00:00

My code is to add RSS feeds to a list – and the code

  • 0

My code is to add RSS feeds to a list – and the code originally was only to pull one feed from the first position in a list, and add this object to another list.

This was the original code:

public static List<Feed> getFeedsFromXml(String xml) {
      Pattern feedPattern = Pattern.compile("<feed>\\s*<name>\\s*([^<]*)</name>\\s*<uri>\\s*([^<]*)</uri>\\s*</feed>");


      Matcher feedMatch = feedPattern.matcher(xml);
      while (feedMatch.find()) {
          String feedName = feedMatch.group(1);
          String feedURI = feedMatch.group(2);
          feeds.add(new Feed(feedName, feedURI));
      }

      return feeds;
}

@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public String addXmlFeed() throws IOException
{
    int i = 0;
    String stringXml = "<feed><name>SMH Top Headlines</name><uri>http://feeds.smh.com.au/rssheadlines/top.xml</uri></feed><feed><name>UTS Library News</name>";
    getFeedsFromXml(stringXml);
    Feed f = (Feed) feeds.get(0);
    feedList.add(f);
    String handler = "You have successfully added: \n"; 
    String xmlStringReply = "" + f + "\n";

    feedList.save(feedFile);
    return handler + xmlStringReply;

}

Everything was going well, and then I decided to implement a for loop for handling the adding of more than one feed to the list, and I tried the following (only the code for the second method in question):

@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public String addXmlFeed() throws IOException
{
    int i = 0;
    String stringXml = "<feed><name>SMH Top Headlines</name><uri>http://feeds.smh.com.au/rssheadlines/top.xml</uri></feed><feed><name>UTS Library News</name>";
    getFeedsFromXml(stringXml);
    for (Feed feed: feeds)
    {
        Feed f = (Feed) feeds.get(i++);
        feedList.add(f);
        String handler = "You have successfully added: \n"; 
        String xmlStringReply = "" + f + "\n";
    }

    feedList.save(feedFile);
    return handler + xmlStringReply;

}

Now I’m sure this is a basic problem, but now in the line:

    return handler + xmlStringReply;

handler and xmlStringReply cannot be resolved to a variable as they are within the FOR LOOP.

Is there any easy way around this?

  • 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-10T13:41:31+00:00Added an answer on June 10, 2026 at 1:41 pm

    The scope of those 2 variables is limited to the for loop. To access them outside the loop, you need to increase their scope by declaring them before the loop:

    String handler = ""; 
    String xmlStringReply = "";
    for (Feed f: feeds) {
        feedList.add(f);
        handler = "You have successfully added: \n"; 
        xmlStringReply = "" + f + "\n";
    }
    
    feedList.save(feedFile);
    return handler + xmlStringReply;
    

    Also, your current code overwrites the value of your strings at each loop, whereas you probably meant to concatenate the values. In that case, you could use a StringBuilder instead of string concatenation:

    StringBuilder xmlStringReply = new StringBuilder("You have successfully added: \n");
    for (Feed f: feeds) {
        feedList.add(f);
        xmlStringReply.append(f + "\n");
    }
    
    feedList.save(feedFile);
    return xmlStringReply.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying the RSS Feed code from this website (http://javamix.wordpress.com/category/programs/rss-feed/) It worked fine.
I've got an Android activity which grabs an RSS feed from a URL, and
I have a website which includes this RSS JavaScript. When I click feed, it
i need to read rss feed from wordpress url. so here is the url
I have the code below to make part of my rss feed a hyperlink
I have a UITableView which from an external RSS feed. When you select a
I am trying to parse an RSS feed with feedparser. The below code snipped
How can I change this code so that I can add it to the
I am writing some code to generate an opml file from a list of
I'm trying to automate the addition of links from an RSS feed to a

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.