Mai*_*nak 6 java xml sax exception
我收到以下异常,但无法找到特定于此异常的任何文档:
org.xml.sax.SAXException: Scanner State 24 not Recognized
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:271)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
Run Code Online (Sandbox Code Playgroud)
任何帮助或指向正确资源的指示都会非常有帮助。
此异常是由 Sun 版本的 Xerces 解析器在 DOM 解析期间产生的。不幸的是,引发异常的特定代码块被隐藏了(以下内容来自JDK 8.0 DOMParser 源代码):
public void parse(InputSource inputSource) throws SAXException, IOException
{
try
{
XMLInputSource xmlInputSource = new XMLInputSource(inputSource.getPublicId(), inputSource.getSystemId(), null);
xmlInputSource.setByteStream(inputSource.getByteStream());
xmlInputSource.setCharacterStream(inputSource.getCharacterStream());
xmlInputSource.setEncoding(inputSource.getEncoding());
parse(xmlInputSource); <-- Original XNIException is thrown in here
} catch (XMLParseException e) {
...
} catch (XNIException e) { // <-- wrap XNI exceptions as SAX exceptions
Exception ex = e.getException();
if (ex == null) { throw new SAXException(e.getMessage()); }
if (ex instanceof SAXException) { throw (SAXException) ex; }
if (ex instanceof IOException) { throw (IOException) ex; }
throw new SAXException(ex); // <-- Note: The original stack trace is lost here.
}
}
Run Code Online (Sandbox Code Playgroud)
由于原始堆栈跟踪被掩盖,因此实际上只有两种方法可以确定此类解析异常的实际原因:
将调试器附加到该DOMParser.parse()方法并单步执行代码以查看最初抛出异常的位置。
从 XML 文档中删除元素,直到不再发生解析错误,然后以较小的增量将它们添加回来,以确定哪个元素/属性/处理指令/等触发了解析器错误。
如果您对查找错误源不感兴趣,只是想消除错误,则可以尝试使用不同的 XML 解析器(例如,最新版本的 Apache Xerces,而不是默认的 Sun Xerces 解析器)。
正如早期评论者所建议的,提供 XML 文档的副本以及特定的 Java 版本(例如 JDK 8.0u40b25)将能够得到更精确的答案。
| 归档时间: |
|
| 查看次数: |
9460 次 |
| 最近记录: |