带有文件URI的MalformedURLException

时间:2010-05-26 19:39:50

标签: xml file uri malformedurlexception dtd-parsing

执行以下代码时:

        doc = builder.parse(file);

其中docorg.w3c.dom.Document的实例而builderjavax.xml.parsers.DocumentBuilder的实例,我遇到以下异常:

Exception in thread "main" java.net.MalformedURLException: unknown protocol: c
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(Unknown Source)
        at java.net.URL.<init>(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.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.DOMParser.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
        at com.acme.ItemToThetaValues.createFiles(ItemToThetaValues.java:47)

文件的这一行令人窒息:

<!DOCTYPE questestinterop SYSTEM "C:\Program Files\Acme\parsers\acme_full.dtd">

我的机器上没有收到此错误,而用户正在他的机器上获取此错误。我们都使用Sun JRE的第6版。当他在路径中使用双反斜杠而不是单个反斜杠时,以及当他使用正斜杠而不是反斜杠时,也会发生此错误。

首先,XML是否正确?路径是否正确表达?其次,为什么这个错误发生在一台计算机上而不发生在另一台计算机上呢?

1 个答案:

答案 0 :(得分:1)

事实证明我们没有使用相同版本的JRE。他正在使用1.6.0_06,而我使用的是java版本“1.6.0_20”。

这是bug in the 1.6.0_06 version of the JRE