我有这个dtd: http://fast-code.sourceforge.net/template.dtd 但是当我在xml中包含时,我得到警告: 没有为文档检测到语法约束(DTD或XML模式)。 xml是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE templates PUBLIC "//UNKNOWN/" "http://fast-code.sourceforge.net/template.dtd">

<templates>
<template type="INSTANCE_OF_CLASS">
    <description>Used to Create instance of class</description>
    <variation>asasa</variation>
    <variation-field>asasa</variation-field>
    <class-pattern>asasa</class-pattern>
    <getter-setter>setter</getter-setter>
    <allowed-file-extensions>java</allowed-file-extensions>
    <number-required-classes>1</number-required-classes>
    <allow-multiple-variation>false</allow-multiple-variation>
    <template-body>
        <![CDATA[
            // Creating new instance of ${class_name}
            final ${class_name} ${instance} = new ${class_name}();
            #foreach ($field in ${fields})
                ${instance}.${field.setter}(${field.value});
            #end
        ]]>
    </template-body>
</template>
</templates>

编辑:我改变了xml,我现在得到这个错误:

元素类型“template”的内容必须匹配“(description,variation?,variation-field?,允许 multiple-variation ?,阶级结构? getter-setter ? allowed-file-extensions吗?阈值- 类?模板体内)”。


当前回答

这在Eclipse 3.7.1中很适用:

转到首选项窗口,然后XML -> XML文件->验证。

然后在右侧首选项面板的“验证文件”部分中,在“不指定语法”首选项的下拉框中选择“忽略”。您可能需要关闭该文件,然后重新打开它以消除警告。

其他回答

添加DOCTYPE标签…

在这种情况下:

<!DOCTYPE xml>

添加后:

<?xml version="1.0" encoding="UTF-8"?>

So:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>

这可能是由于关闭了eclipse中的验证。

这在Eclipse 3.7.1中很适用:

转到首选项窗口,然后XML -> XML文件->验证。

然后在右侧首选项面板的“验证文件”部分中,在“不指定语法”首选项的下拉框中选择“忽略”。您可能需要关闭该文件,然后重新打开它以消除警告。

我知道这是旧的,但我通过同样的问题,并在春季文档中找到了解决方案,以下xml配置已经为我解决了这个问题。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx 

<!-- THIS IS THE LINE THAT SOLVE MY PROBLEM -->
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 

http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

在我把上面的行建议在这个论坛的主题,我有同样的警告信息,并把这个…

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>

它给了我以下警告信息…

The content of element type "template" must match "
(description,variation?,variation-field?,allow- multiple-variation?,class-
pattern?,getter-setter?,allowed-file-extensions?,number-required- 
classes?,template-body)".

因此,请尝试使用我的XML配置中的建议行。

What I found to be the solution was something very very simple that I think you should try before tinkering with the preferences. In my case I had this problem in a strings file that had as a base tag "resources" ...all I did was delete the tag from the top and the bottom, clean the project, save the file and reinsert the tag. The problem has since disappeared and never gave me any warnings. It may sound to simple to be true but hey, sometimes it's the simplest things that solve the problems. Cheers