Referring to a local DTD in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 02:35:41

Take a look at this article on using XML catalogs to resolve DTDs locally without having to modify your XML source. The basic steps are:

  1. create an XML file that maps system IDs to local DTDs
  2. modify your code to instantiate and configure a CatalogResolver
  3. provide the CatalogResolver to the XML Reader (obtained from the parser)

When dealing with Web Apps, you can put the dtd in the lib folder and refer to it like:

<!DOCTYPE name PUBLIC 
    "-//CMP//DTD dtdName 1.0//EN"
        "/WEB-INF/lib/dtdName.dtd">

The solution is to provide the DTD file location in the system using classpath. So the DocType that worked offline would be:

<!DOCTYPE hibernate-configuration SYSTEM 
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

Also another way can be to keep the dtd at the localhost so that the final path becomes something like:

<!DOCTYPE hibernate-configuration SYSTEM 
          "http://localhost/hibernate-configuration-3.0.dtd">

Definitely not the most elegant solution but surely does work.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!