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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:46:55+00:00 2026-06-10T14:46:55+00:00

I am working on a RESTful web service, that will return a list of

  • 0

I am working on a RESTful web service, that will return a list of RSS feeds that someone has added to a feed list which I have previously implemented.

Now if I return a TEXT_PLAIN reply, this displays just fine in the browser, although when I attempt to return an APPLICATION_XML reply, then I get the following error:

XML Parsing Error: junk after document element
Location: http:// localhost:8080/Assignment1/api/feedlist
Line Number 1, Column 135:SMH Top Headlineshttp://feeds.smh.com.au/rssheadlines/top.xmlUTS Library Newshttp://www.lib.uts.edu.au/news/feed/all

Here is the code – I cannot figure out why it is not returning a well formed XML page (I have also tried formatting the XML reply with new lines and spaces(indents) – and of course this did not work):

package au.com.rest;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import au.edu.uts.it.wsd.*;


@Path("/feedlist")
public class RESTFeedService {

String feedFile = "/tmp/feeds.txt"; 
String textReply = "";
String xmlReply = "<?xml version=\"1.0\"?><feeds>";
FeedList feedList = new FeedListImpl();

@GET
@Produces(MediaType.APPLICATION_XML)
public String showXmlFeeds() throws FileNotFoundException, IOException
{

    feedList.load(feedFile);
    for (Feed f:feedList.list()){
        xmlReply += "<feed><name>" + f.getName() + "</name>";
        xmlReply += "<uri>" + f.getURI() + "</uri></feed></feeds>";
    }

    return xmlReply;
}

}
  • 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-10T14:46:57+00:00Added an answer on June 10, 2026 at 2:46 pm

    EDIT: I’ve spotted the immediate problem now. You’re closing the feeds element on every input element:

    for (Feed f:feedList.list()){
        xmlReply += "<feed><name>" + f.getName() + "</name>";
        xmlReply += "<uri>" + f.getURI() + "</uri></feed></feeds>";
    }
    

    The minimal change would be:

    for (Feed f:feedList.list()){
        xmlReply += "<feed><name>" + f.getName() + "</name>";
        xmlReply += "<uri>" + f.getURI() + "</uri></feed>";
    }
    xmlReply += "</feeds>";
    

    … but you should still apply the rest of the advice below.


    First step – you need to diagnose the problem further. Look at the source in the browser to see exactly what it’s complaining about. Can you see the problem in the XML yourself? What does it look like?

    Without knowing about the rest framework you’re using, this looks like it could be a
    problem to do with a single instance servicing multiple requests. For some reason you’ve got an instance variable which you’re mutating in your method. Why would you want to do that? If a new instance of your class is created for each request, it shouldn’t be a problem – but I don’t know if that’s the case.

    As a first change, try moving this line:

    String xmlReply = "<?xml version=\"1.0\"?><feeds>";
    

    into the method as a local variable.

    After that though:

    • Keep all your fields private
    • Avoid using string concatenation in a loop like this
    • More importantly, don’t build up XML by hand – use an XML API to do it. (The built-in Java APIs aren’t nice, but there are plenty of alternatives.)
    • Consider which of these fields (if any) is really state of the object rather than something which should be a local variable. What state does your object logically have at all?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an enterprise system that will utilise a RESTful web service
I've been trying to do a simple restful wcf service that will return JSON.
I have a (semi)RESTful web service that I'm working on written in c++. We
I'm working on a RESTful web service in Java. I need a good way
I am working on a project in which a WCF service will be consumed
I am working in a iPhone project that uses restful web services. I need
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
I've been working off an example (http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-45.html) and I've been debugging some issues and
For a RESTful web service we say that that the server shouldn't store any
I'm working on a RESTful web-service with the WCF Web API. Another party provided

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.