我有这个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文件->验证。

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

其他回答

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

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

您是否尝试将模式添加到xml目录?

在eclipse中,为避免“没有为文档检测到语法约束(dtd或XML模式)”,我使用XSD模式文件添加到下的XML编目

“窗口\首选项\ xml \ xml目录\用户指定的条目”。

点击右侧的“添加”按钮。


例子:

<?xml version="1.0" encoding="UTF-8"?>
<HolidayRequest xmlns="http://mycompany.com/hr/schemas">
    <Holiday>
        <StartDate>2006-07-03</StartDate>
        <EndDate>2006-07-07</EndDate>
    </Holiday>
    <Employee>
        <Number>42</Number>
        <FirstName>Arjen</FirstName>
        <LastName>Poutsma</LastName>
    </Employee>
</HolidayRequest>

从这个xml中我生成并保存了一个xsd: /home/my_user/xsd/my_xsd.xsd

As位置:/home/my_user/xsd/my_xsd.xsd

As键类型:命名空间名称

作为键:http://mycompany.com/hr/schemas


关闭并重新打开xml文件并做一些更改来违反模式,您应该会收到通知

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

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

<?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

这在Eclipse 3.7.1中很适用:

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

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