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


当前回答

试着理解警告信息中给出的建议,这有时是有帮助的。

我也有同样的问题,在做了一些研究后,我找到了解决方案,并在开头添加了下面的一行

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE 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

我通过指定<!来消除这个恼人的警告。DOCTYPE xml> <?xml……>标记,而不是指定其他内容(如在您的情况下的模板)。

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

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

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

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

试着理解警告信息中给出的建议,这有时是有帮助的。

我也有同样的问题,在做了一些研究后,我找到了解决方案,并在开头添加了下面的一行

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

这就引出了我的另一个问题。 我通过阅读建议解决了这个问题,这又变成了另一个问题,这个问题已经解决了,理解了最初的原因,第一个链接被打破了(没有找到)。下面是一步一步的图片,解释了已经做了什么来完全解决这个问题。

我在xsi:noNamespaceSchemaLocation中使用了相对路径来提供本地xsd文件(因为我不能在实例xml中使用名称空间)。

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../project/schema.xsd">
</root>

验证有效,警告被修复(没有被忽略)。

https://www.w3schools.com/xml/schema_example.asp