我有这个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:

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

<rootElement>
 ....
</rootElement>

以上内容适用于Eclipse Juno+

其他回答

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

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

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

<rootElement>
 ....
</rootElement>

以上内容适用于Eclipse Juno+

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