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

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

其他回答

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

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

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

您是否尝试将模式添加到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文件并做一些更改来违反模式,您应该会收到通知

下面是这个问题的有效解决方案:


步骤1:右键单击项目并进入属性

步骤2:转到“libraries”,删除项目的“JRE系统库”

步骤3:点击“添加库”——>“JRE系统库”——>选择“工作区默认JRE”

步骤3:转到“订购和导出”,并标记新添加的“JRE系统库”

步骤4:刷新和清理项目

尤里卡!它正在工作:)

在记事本中复制您的整个代码。 临时以任何名称保存文件[在保存文件时使用"encoding" = UTF-8(或更高,但UTF)]。 关闭文件。 再打开一遍。 复制粘贴到代码中。

错误必须消失。

我知道这是旧的,但我通过同样的问题,并在春季文档中找到了解决方案,以下xml配置已经为我解决了这个问题。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx 

<!-- THIS IS THE LINE THAT SOLVE MY PROBLEM -->
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 

http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

在我把上面的行建议在这个论坛的主题,我有同样的警告信息,并把这个…

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

它给了我以下警告信息…

The content of element type "template" must match "
(description,variation?,variation-field?,allow- multiple-variation?,class-
pattern?,getter-setter?,allowed-file-extensions?,number-required- 
classes?,template-body)".

因此,请尝试使用我的XML配置中的建议行。