在执行以下代码时:
doc = builder.parse(file);
wheredoc
是 的一个实例org.w3c.dom.Document
并且builder
是 的一个实例javax.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 是否正确?路径表达是否正确?其次,为什么这个错误发生在一台计算机上而不是另一台计算机上?