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


当前回答

真正的解决方案:

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

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

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

其他回答

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

在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文件并做一些更改来违反模式,您应该会收到通知

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

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

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

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

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

<rootElement>
 ....
</rootElement>

以上内容适用于Eclipse Juno+

这可能是由于关闭了eclipse中的验证。