【发布时间】:2011-04-04 23:18:27
【问题描述】:
我有一个从 3rd 方源解组 xml 的类(我无法控制内容)。这是解组的 sn-p:
JAXBContext jContext = JAXBContext.newInstance("com.optimumlightpath.it.aspenoss.xsd");
Unmarshaller unmarshaller = jContext.createUnmarshaller() ;
StringReader xmlStr = new StringReader(str.value);
Connections conns = (Connections) unmarshaller.unmarshal(xmlStr);
Connections 是使用 xjc 生成的 dtd->xsd->class 类。包com.optimumlightpath.it.aspenoss.xsd 包含所有这些类。
我收到的 xml 在 DOCTYPE 中包含相对路径。基本上str.value上面包含:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE Connections SYSTEM "./dtd/Connections.dtd">
<Connections>
...
</Connections>
这可以作为 java 1.5 应用程序成功运行。为了避免上述错误,我必须在项目根目录下创建一个 ./dtd 目录并包含所有 dtd 文件(不知道为什么我必须这样做,但我们会解决的)。
我已经在 Tomcat5.5 上创建了一个使用上述类的 Web 服务。我在解组线上收到[org.xml.sax.SAXParseException: Relative URI "./dtd/Connections.dtd"; can not be resolved without a document URI.]。我尝试在每个相关文件夹(项目根目录、WebContent、WEB-INF、tomcat 工作目录等)中创建 ./dtd,但无济于事。
问题 #1:我在哪里可以找到 ./dtd 以便类在作为 tomcat Web 服务运行时可以找到它?为了让目录被识别,我需要做任何 tomcat 或服务配置吗?
问题 #2:为什么类首先需要 dtd 文件?它没有在 dtd->xsd->class 的注释中解组所需的所有信息吗?我已经阅读了很多关于禁用验证、设置 EntityResource 和其他解决方案的帖子,但是这个类并不总是部署为 Web 服务,我不希望有两个代码序列。
【问题讨论】: