Java Eclipse 中的 SaxParseException:XML 文档结构必须在同一实体内开始和结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23156292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 21:05:53  来源:igfitidea点击:

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

javaxmleclipsesaxlast.fm

提问by HackCode

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

我正在使用用于 JAVA 的 last.fm API,可以在此处找到。

I have a huge Datasetin 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.

我有一个巨大的数据集,其中我只使用包含用户艺术家历史和播放的文件。我用 Java 编写了一个代码,它提取这些艺术家姓名并根据Artist.getSimilar()方法返回相似的艺术家。

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:

我运行了一次,但不是为所有艺术家运行。我中途终止了调试。但是下一次,我的结果是从缓存中返回的,不再是将请求发送到网络服务器。问题是,这次我只得到结果,直到我终止结果的艺术家。我尝试对 使用另一种方法,在artists=Artist.getTopAlbums()那里我中途终止,下次遇到同样的问题。我得到的错误是:

[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 -cleanmode 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).

我尝试重新安装 eclipse,以-clean模式启动 eclipse并清理工作区。没有任何效果。我也创建了一个新工作区,但缓存不断返回。我正在使用 Eclipse 3.8 。也许在 Eclipse 中清除缓存的有效方法会有所帮助?我该怎么做。似乎没有任何效果。(此外,许多文章中都建议在“窗口”>“首选项”中手动清理缓存没有选项)。

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):

我的 Java 代码(运行良好,没有错误):

//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

回答by Mike Thomsen

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

引起:org.xml.sax.SAXParseException;行号:513;列数:9;XML 文档结构必须在同一实体内开始和结束。在

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)
  1. 将 XML 文档打印到日志中并通过某种 XML 验证器运行它。
  2. 检查以确保没有无效字符(例如 UTF-8 文档中的 UTF-16 字符)

回答by Konstantin Komissarchik

Neither Eclipse nor Java cache web content when doing regular I/O. The content can be cached somewhere else, though. Perhaps de.umass.lastfm API that you are using is doing this. Perhaps there is something in your OS or on your network.

在进行常规 I/O 时,Eclipse 和 Java 都不会缓存 Web 内容。不过,内容可以缓存在其他地方。也许您正在使用的 de.umass.lastfm API 正在执行此操作。也许您的操作系统或网络中存在某些问题。