How to use DOCTYPE in Spring XML file

落花浮王杯 提交于 2019-12-08 10:23:39

问题


Most of the time we do not declare DOCTYPE in Spring. But I want to declare a DOCTYPE in my XML context file so that I can use ENTITY in my xml file.

For example:

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
                  "http://www.springframework.org/dtd/spring-beans-2.0.dtd"
    [<!ENTITY % crmHome SYSTEM "crm-home.dtd"> %crmHome;]
>

This gives many errors like...

 - Attribute "xmlns" must be declared for element type "beans".

 - Attribute "xmlns:xsi" must be declared for element type "beans".

    etc.....

What is the way to achieve this?


回答1:


This works for me. Using Spring Framework V.4.2.1

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">



回答2:


If you're using schema validation anyway then you could just define the internal DTD subset sufficient to declare the parameter entity and not refer to the http://www.springframework.org/dtd/spring-beans-2.0.dtd:

<!DOCTYPE beans [
  <!ENTITY % crmHome SYSTEM "crm-home.dtd">
   %crmHome;
]>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
             http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans.xsd">


来源:https://stackoverflow.com/questions/14378767/how-to-use-doctype-in-spring-xml-file

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