我有这个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吗?阈值- 类?模板体内)”。


当前回答

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

其他回答

真正的解决方案:

添加一个< !DOCTYPE >到每个有问题的XML的开头,

在XML标记<?XML版本="1.0"编码="utf-8"?>

你可以为doctype写任何东西,但基本上它应该是manifest, activity等,从我的理解

下面是这个问题的有效解决方案:


步骤1:右键单击项目并进入属性

步骤2:转到“libraries”,删除项目的“JRE系统库”

步骤3:点击“添加库”——>“JRE系统库”——>选择“工作区默认JRE”

步骤3:转到“订购和导出”,并标记新添加的“JRE系统库”

步骤4:刷新和清理项目

尤里卡!它正在工作:)

添加DOCTYPE标签…

在这种情况下:

<!DOCTYPE xml>

添加后:

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

So:

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

对我来说,这是一个字符编码和unix文件模式在Windows上运行eclipse的问题:

只需标记完整的代码,剪切并粘贴回来(简而言之:CtrlA-CtrlX-CtrlV),一切都很好-没有“没有语法限制…”警告

我真的不能说为什么会出现“No grammar constraints…”警告,但是我可以在Eclipse中通过完全删除DOCTYPE声明来引起它。当我把声明放回去并再次验证时,我得到了这个错误消息:

元素类型template的内容 必须匹配 ”(描述+、变异? variation-field ?, allow-multiple-variation ?,阶级结构?,getter-setter ?, allowed-file-extensions ?,模板体内+)。

我相信这是正确的(“number-required-classes”元素是不允许的)。