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

26,379

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)
Share:
26,379
HackCode
Author by

HackCode

Updated on January 13, 2020

Comments

  • HackCode
    HackCode over 4 years

    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
    
  • HackCode
    HackCode about 10 years
    I have got nothing to do with the XML file. As I said,the code works perfectly fine for any method listed in the API,until I terminate it while it is still running. In that case,next time,it only shows till the result where I had terminated it.
  • Konstantin Komissarchik
    Konstantin Komissarchik about 10 years
    Sure it does. The author theorizes that Eclipse is caching web requests. I am stating that it doesn't and pointing at other places to look. The answer does not need to provide a finished solution to be useful.
  • Adi Inbar
    Adi Inbar about 10 years
    I agree with @Deduplicator. "Answer" at SO doesn't mean just any response that's useful, it's defined as something that provides an answer to the question (not in the sense of "reply" or "response"; in the sense of resolving the issue raised in the question). A remark clearing up a misconception in the question and giving vague advice about which general areas to look at in seeking a solution is not a valid answer. This should be a comment.
  • Konstantin Komissarchik
    Konstantin Komissarchik about 10 years
    My answer directly addresses the questions raised in the question. It does not provide a complete solution, but it is a stretch to say that it doesn't answer the questions raised.
  • Adi Inbar
    Adi Inbar about 10 years
    Well, it's in the LQP review queue (where I encountered it), and the current vote is 4-0 in favor of deletion. You seem to be interpreting "answer" in the sense of "response". I didn't say it doesn't address the issues raised in the question; I'm saying that "answer" doesn't mean any response that addresses the issues in the question. The OP is asking why this is happening, and this "answer" doesn't even partially explain why, it basically just says "Java and Eclipse wouldn't produce this problem, so look elsewhere". I can't see that as an answer. It's up to the community to decide...
  • Konstantin Komissarchik
    Konstantin Komissarchik about 10 years
    By your definition of answer, half of answers on SO would not qualify. In practice, it is an answer if it addresses some of the questions raised, which mine does. The accepted answer is the one that strikes the closes to a full solution, which is often not possible. So is it better to have partial answer or no answers?
  • Adi Inbar
    Adi Inbar about 10 years
    We may disagree on this, but it's certainly not because my definition of "answer" is skewed. I'd estimate that by my definition over 99% of answers at SO that don't get deleted qualify. That's based on having done thousands of reviews and nearly always going back to check how others voted, and on having raised roughly 300 "not an answer" flags and only having one declined. That's a pretty clear indication that my understanding of what is and isn't an answer is not out of step with community standards.
  • Adi Inbar
    Adi Inbar about 10 years
    BTW...I do think partial answers are better than no answers, but a partial answer would partially explain why this is happening. I'm really having a hard time seeing how just saying "Java and Eclipse don't cache, look elsewhere for a reason" qualifies as an answer. By that standard, SO would end up resembling all those tech forums where you have to sift through endless comments, pointers, and discussion to see if there's a solution buried somewhere. It's exceptionally rare to see something like this posted by a high rep user as an answer rather than a comment.