SaxParseException in eclipse: XML document structures must start and end within the same entity

HackCode picture HackCode · Apr 18, 2014 · Viewed 25.9k times · Source

I am using the last.fm API for JAVA which can be found here .

I have a huge Dataset in which I am only using the file with user's artist history and plays. I have written a code in Java which extracts these artist names and returns the similar artists based on Artist.getSimilar() method.

I ran it once but not for all the artists. I terminated the debugging half way through. However next time,my results were being returned from the cache and no longer was the request sent to the web-server. The problem is, this time I am getting results only till the artist where I had terminated the results. I tried using another method for the artists=Artist.getTopAlbums(), where I terminated mid way and faced the same problem next time. The error I am getting is:

[Fatal Error] :513:9: <strong>XML document structures must start and end within the same entity.</strong>
Exception in thread "main" de.umass.lastfm.CallException: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.
Caused by: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:251)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)

and a bunch of other exceptions which is not the important part here.

I tried reinstalling eclipse, starting eclipse in -clean mode and cleaning the workspace. Nothing worked. I created a new workspace too but the cache keeps coming back. I am using Eclipse 3.8 . Maybe an efficient way to clear the cache in eclipse would help? How would I do that. Nothing seems to work. (Also there is no option to manually clean the cache in Window>Preferences as was suggested in many articles).

Or do I need to do something else? Any help is much appreciated. Thanks in advance.

My java code (which is working perfectly fine,no errors in this):

//in main
BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
String sinput=inp.readLine();
System.out.println(sinput+"\t \t \t"+getSimilarartists(sinput));


//to fetch similar artists
public static StringBuilder getSimilarartists(String artist){
String key = "af2bfbcb4dd49870fdb8e92f128f4ff7";
StringBuilder sb = new StringBuilder();
String art=(Artist.getSimilar(artist, key)).toString();
int i=0;
while(i<art.length()-5){
    if((art.substring(i, (i+4))).equalsIgnoreCase("name")){
        i=i+6;

        while(art.charAt(i)!='\''){
            sb.append(art.charAt(i));
            i++;
        }

        break;
    }
    i++;
}
return sb;
}  

Output(just the last few lines):

hans zimmer;     I recommend=Hans Zimmer & James Newton Howard<br>
nelly furtado;   I recommend=Jennifer Lopez<br>
madonna;     I recommend=Kylie Minogue<br>
blink-182;   I recommend=Box Car Racer<br>
dave gahan;  I recommend=Depeche Mode<br>
kelly clarkson;  I recommend=Carrie Underwood<br>
lucie silvas;    I recommend=Delta Goodrem<br>
natalie imbruglia;   I recommend=Melanie C<br>
michelle branch;     I recommend=The Wreckers<br>
delta goodrem;   I recommend=Ricki-Lee<br>
new order;   I recommend=Electronic<br>
seal;    I recommend=Simply Red<br>
atomic kitten;   I recommend=Liberty X 

 *** (this is where I had terminated my previous run) ***

[Fatal Error] :513:9: XML document structures must start and end within the same entity.<br>
Exception in thread "main" de.umass.lastfm.CallException: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.
    at de.umass.lastfm.Caller.call(Caller.java:268)<br>
    at de.umass.lastfm.Caller.call(Caller.java:189)<br>
    at de.umass.lastfm.Caller.call(Caller.java:185)<br>
    at de.umass.lastfm.Artist.getSimilar(Artist.java:144)<br>
    at de.umass.lastfm.Artist.getSimilar(Artist.java:132)<br>
    at Recommender.getSimilarartists(Recommender.java:89)<br>
    at Recommender.main(Recommender.java:58)<br>
Caused by: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity.<br>
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:251)
    at     <br>
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)<br>
    at de.umass.lastfm.Caller.createResultFromInputStream(Caller.java:324)<br>
    at de.umass.lastfm.Caller.call(Caller.java:256)<br>
    ... 6 more

Answer

Mike Thomsen picture Mike Thomsen · Apr 18, 2014

Errors like this are usually indicative of a badly formatted document:

Caused by: org.xml.sax.SAXParseException; lineNumber: 513; columnNumber: 9; XML document structures must start and end within the same entity. at

A few things you can do to debug this:

  1. Print out the XML document to a log and run it through some sort of XML validator.
  2. Check to make sure that there are no invalid characters (ex UTF-16 characters in a UTF-8 document)