Dom 解析器在解析公共(public) id 存在但系统 id 不存在的 xml 文件时给出以下异常。
例如:
<!DOCTYPE SPIN PUBLIC "-//AIP//DTD aipspin//EN"> <root> ... </root>
org.xml.sax.SAXParseException: White spaces are required between publicId and systemId. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:180) at com.main.parse.main(parse.java:77)
一种解决方法是更改添加虚拟系统 ID 和空格,但我无法在 xml 文件中进行手动更改。
有什么办法可以通过代码来调整吗?
最佳答案
您可能使用了公司的代理,并且您的网络可能无法解析 xsd 文件的 URL。
要解决这个问题,您可以尝试以下方法- 将 xsd 或 xml 文件的 URL 替换为类路径的版本。
示例:
替换 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 和 类路径:org/springframework/beans/factory/xml/spring-beans-2.5.xsd
为我工作..
关于java - publicId 和 systemId 之间需要空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28496555/