我有这个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.5.2中解决了此问题。两个完全相同的布局,其中一个有警告。关闭所有标签,重新打开时,警告已经消失。

其他回答

这在Eclipse 3.7.1中很适用:

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

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

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

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

我在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

一种新的干净的方法可能是这样写xml:

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

<rootElement>
 ....
</rootElement>

以上内容适用于Eclipse Juno+

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

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