无法解析JavaHelp的toc.xml

时间:2010-09-13 21:17:47

标签: xml dtd javahelp

我为JavaHelp的toc.xml文件编写了一个XML解析器,以拦截我在tocitem标记中使用的一些被JavaHelp忽略的属性。这是toc.xml的样子:

<?xml version='1.0' encoding='ISO-8859-1'  ?>

<!DOCTYPE toc
   PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 2.0//EN"
     "http://java.sun.com/products/javahelp/toc_2_0.dtd">
<toc version="2.0">
   <tocitem text="Introduction" target="intro" action="myapp.help.introAction"/>
</toc>

我正在使用标准SAX解析器解析toc.xml。当我解析文件时,我得到以下异常:

myapp.help.TOCTreeFactory[WARN]: Failed to load TOC file from 'jar:file:/home/samad/myapp.jar!/workflow-help/toc.xml'

Caused by:
http://java.sun.com/javase/technologies/desktop/javahelp/toc_2_0.dtd
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at myapp.help.TOCTreeFactory.createTree(TOCTreeFactory.java:43)
...

我打开了网址http://java.sun.com/javase/technologies/desktop/javahelp/toc_2_0.dtd,我得到了404。

如何解决此问题?我尝试下载JavaHelp发行版,但它不包含SAX所需的toc_2_0.dtd文件。

2 个答案:

答案 0 :(得分:1)

您是否尝试在工厂中关闭验证?

SAXParserFactory pf = SAXParserFactory.newInstance();
pf.setValidating(false);

另一种选择...... Stop your Java SAX parser from downloading DTDs

答案 1 :(得分:0)

在寻找类似问题的解决方案时,我首先被引导到这个问题。 setValidating()方法对我也不起作用。 This answer related question SAXParserFactory指向setFeature() method的{{3}},{{3}}确实有效。

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);