未检测到文档的语法约束(DTD 或 XML 模式)

发布于 2024-10-09 09:32:35 字数 1505 浏览 0 评论 0原文

我有这个 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?,allow- 多重变体?,类模式?,getter-setter?,允许的文件扩展名?,需要数量- 类?,模板主体)”。

I have this dtd : http://fast-code.sourceforge.net/template.dtd
But when I include in an xml I get the warning :
No grammar constraints (DTD or XML schema) detected for the document.
The xml is :

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

EDIT : I changed the xml, I am getting this error now:

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)".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

甜宝宝 2024-10-16 09:32:35

我通过在 标记后面指定 而不是指定其他内容(例如 模板在你的情况下)。

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

I got rid of this annoying warning by specifying <!DOCTYPE xml> after the <?xml ... > tag instead of specifying something else (like templates in your case).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
恍梦境° 2024-10-16 09:32:35

这在 Eclipse 3.7.1 中对我有用:

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

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

This worked for me in Eclipse 3.7.1:

Go to the Preferences window, then XML -> XML Files -> Validation.

Then in the Validating files section of the preferences panel on the right, choose Ignore in the drop down box for the "No grammar specified" preference. You may need to close the file and then reopen it to make the warning go away.

暗恋未遂 2024-10-16 09:32:35

答案:

对下面的 DTD 的每部分进行评论。请参阅官方规范了解更多信息。

  <!
  DOCTYPE ----------------------------------------- correct
  templates --------------------------------------- correct  Name matches root element.
  PUBLIC ------------------------------------------ correct  Accessing external subset via URL.
  "//UNKNOWN/" ------------------------------------ invalid? Seems useless, wrong, out-of-place.
                                                             Safely replaceable by DTD URL in next line.
  "http://fast-code.sourceforge.net/template.dtd" - invalid  URL is currently broken.
  >

简单说明:

极其基本的 DTD 将类似于此处的第二行

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nameOfYourRootElement>
<nameOfYourRootElement>
</nameOfYourRootElement>

详细说明:

DTD 用于建立商定的数据格式并验证收到此类数据。它们定义了 XML 文档的结构,包括:

  • 合法元素列表、
  • 特殊字符、
  • 字符串
  • 更多

例如

<!DOCTYPE nameOfYourRootElement
[
<!ELEMENT nameOfYourRootElement (nameOfChildElement1,nameOfChildElement2)>
<!ELEMENT nameOfChildElement1 (#PCDATA)>
<!ELEMENT nameOfChildElement2 (#PCDATA)>
<!ENTITY nbsp " "> 
<!ENTITY author "Your Author Name">
]>

:上面几行...
第 1 行)根元素定义为“nameOfYourRootElement”
第 2 行)元素定义的开始
第 3 行)根元素子级定义为“nameOfYourRootElement1”和“nameOfYourRootElement2”
第4行)子元素,定义为数据类型#PCDATA
第5行)子元素,定义为数据类型#PCDATA
第 6 行) 当 XML 解析器解析文档时,将   实例扩展为  
第 7 行)当 XML 解析器解析文档时,将 &author; 实例扩展为 Your Author Name
第 8 行) 定义结束

Answer:

Comments on each piece of your DTD below. Refer to official spec for more info.

  <!
  DOCTYPE ----------------------------------------- correct
  templates --------------------------------------- correct  Name matches root element.
  PUBLIC ------------------------------------------ correct  Accessing external subset via URL.
  "//UNKNOWN/" ------------------------------------ invalid? Seems useless, wrong, out-of-place.
                                                             Safely replaceable by DTD URL in next line.
  "http://fast-code.sourceforge.net/template.dtd" - invalid  URL is currently broken.
  >

Simple Explanation:

An extremely basic DTD will look like the second line here:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nameOfYourRootElement>
<nameOfYourRootElement>
</nameOfYourRootElement>

Detailed Explanation:

DTDs serve to establish agreed upon data formats and validate the receipt of such data. They define the structure of an XML document, including:

  • a list of legal elements
  • special characters
  • character strings
  • and a lot more

E.g.

<!DOCTYPE nameOfYourRootElement
[
<!ELEMENT nameOfYourRootElement (nameOfChildElement1,nameOfChildElement2)>
<!ELEMENT nameOfChildElement1 (#PCDATA)>
<!ELEMENT nameOfChildElement2 (#PCDATA)>
<!ENTITY nbsp " "> 
<!ENTITY author "Your Author Name">
]>

Meaning of above lines...
Line 1) Root element defined as "nameOfYourRootElement"
Line 2) Start of element definitions
Line 3) Root element children defined as "nameOfYourRootElement1" and "nameOfYourRootElement2"
Line 4) Child element, which is defined as data type #PCDATA
Line 5) Child element, which is defined as data type #PCDATA
Line 6) Expand instances of   to   when document is parsed by XML parser
Line 7) Expand instances of &author; to Your Author Name when document is parsed by XML parser
Line 8) End of definitions

折戟 2024-10-16 09:32:35

真正的解决方案

添加到每个有问题的 XML 的开头,

位于 xml 标记

你可以为 doctype 编写任何内容,但根据我的理解,基本上它应该是清单、活动等

The Real Solution:

add <!DOCTYPE something> to the begining of each problematic XML,

after the xml tag <?xml version="1.0" encoding="utf-8"?>

you can write anything for doctype, but basically it's supposed to be manifest, activity, etc. from what I understand

撑一把青伞 2024-10-16 09:32:35

您是否尝试过将架构添加到 xml 目录?

在 Eclipse 中避免“检测到文档没有语法约束(dtd 或 xml 模式)”。我用来将 xsd 架构文件添加到

“Window \preferences\xml\xmlcatalog\Userspecifiedentries”下的 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

作为位置:/home/my_user/xsd/my_xsd.xsd

作为密钥类型:命名空间名称

作为密钥:http://mycompany.com/hr/schemas


关闭并重新打开 xml 文件并进行一些更改以违反架构,您应通知

Have you tried to add a schema to xml catalog?

in eclipse to avoid the "no grammar constraints (dtd or xml schema) detected for the document." i use to add an xsd schema file to the xml catalog under

"Window \ preferences \ xml \ xml catalog \ User specified entries".

Click "Add" button on the right.


Example:

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

From this xml i have generated and saved an xsd under: /home/my_user/xsd/my_xsd.xsd

As Location: /home/my_user/xsd/my_xsd.xsd

As key type: Namespace name

As key: http://mycompany.com/hr/schemas


Close and reopen the xml file and do some changes to violate the schema, you should be notified

请你别敷衍 2024-10-16 09:32:35

添加 DOCTYPE 标签...

在本例中:

<!DOCTYPE xml>

添加后:

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

所以:

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

Add DOCTYPE tag ...

In this case:

<!DOCTYPE xml>

Add after:

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

So:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
往日 2024-10-16 09:32:35

尝试理解警告消息中给出的建议,有时会有帮助。

我也遇到了同样的问题,经过一些研究后,我找到了解决方案并通过在开头添加以下行来修复,

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

这导致了我的案例中的一些其他问题。
我通过阅读建议解决了这个问题,这又变成了另一个问题,该问题已通过理解原始原因得到解决,即第一个链接已损坏(未找到)。下面是分步图像,解释了为彻底解决该问题而采取的措施。

输入图像描述此处

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Try understanding the suggestion given in warning messages, it's helps sometime.

I also had the same issues, after doing some research i found the solution and fixed by adding the below line at the beginning

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

which lead to some other issue in my case.
Which i solved by reading the suggestions, which again turned into the another problem, which has been solved understanding the original cause, that the first link was broken (not found). Below are the step by step images which explains what has been done to resolve the issue completely.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

无风消散 2024-10-16 09:32:35

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

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

<rootElement>
 ....
</rootElement>

以上工作在 Eclipse Juno+ 中

A new clean way might be to write your xml like so:

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

<rootElement>
 ....
</rootElement>

The above works in Eclipse Juno+

我一直都在从未离去 2024-10-16 09:32:35

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

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

For me it was a Problem with character encoding and unix filemode running eclipse on Windows:

Just marked the complete code, cutted and pasted it back (in short: CtrlA-CtrlX-CtrlV) and everything was fine - no more "No grammar constraints..." warnings

谷夏 2024-10-16 09:32:35

我真的不能说为什么你会收到“无语法约束...”警告,但我可以通过完全删除 DOCTYPE 声明在 Eclipse 中引发它。当我放回声明并再次验证时,我收到以下错误消息:

元素类型“template”的内容
必须匹配
“(描述+,变体?,变体字段?,允许多个变体?,类模式?,getter-setter?,允许的文件扩展名?,模板主体+)。

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

I can't really say why you get the "No grammar constraints..." warning, but I can provoke it in Eclipse by completely removing the DOCTYPE declaration. When I put the declaration back and validate again, I get this error message:

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

And that is correct, I believe (the "number-required-classes" element is not allowed).

囍笑 2024-10-16 09:32:35

我知道这已经很旧了,但我遇到了同样的问题,并在 spring 文档中找到了解决方案,以下 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 配置的建议行。

i know this is old but I'm passing trought the same problem and found the solution in the spring documentation, the following xml configuration has been solved the problem for me.

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

before I put the line above as sugested in this forum topic , I have the same warning message, and placing this...

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

and it give me the following warning message...

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)".

so just try to use the sugested lines of my xml configuration.

念﹏祤嫣 2024-10-16 09:32:35

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

This may be due to turning off validation in eclipse.

何其悲哀 2024-10-16 09:32:35

在 Eclipse 3.5.2 中解决了这个问题。两个完全相同的布局,其中一个有警告。关闭所有选项卡,重新打开时警告消失。

Solved this issue in Eclipse 3.5.2. Two completely identical layouts of which one had the warning. Closed down all tabs and when reopening the warning had disappeared.

旧城烟雨 2024-10-16 09:32:35
  1. 将整个代码复制到记事本中。
  2. 暂时以任意名称保存文件[保存文件时使用“encoding”= UTF-8(或更高但UTF)]。
  3. 关闭文件。
  4. 再次打开它。
  5. 将其复制粘贴回您的代码中。

错误必须消失。

  1. copy your entire code in notepad.
  2. temporarily save the file with any name [while saving the file use "encoding" = UTF-8 (or higher but UTF)].
  3. close the file.
  4. open it again.
  5. copy paste it back on your code.

error must be gone.

末蓝 2024-10-16 09:32:35

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

I used a relative path in the xsi:noNamespaceSchemaLocation to provide the local xsd file (because I could not use a namespace in the instance xml).

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../project/schema.xsd">
</root>

Validation works and the warning is fixed (not ignored).

https://www.w3schools.com/xml/schema_example.asp

丿*梦醉红颜 2024-10-16 09:32:35

我在 eclipse 中使用 web.xml 文件也遇到了同样的问题
它向我展示了“文档中没有引用语法约束”,

但可以通过添加标签来解决
在 xml 标记之后,即

I too had the same problem in eclipse using web.xml file
it showed me this " no grammar constraints referenced in the document "

but it can be resolved by adding tag
after the xml tag i.e. <?xml version = "1.0" encoding = "UTF-8"?>

顾忌 2024-10-16 09:32:35

以下是此问题的有效解决方案:


步骤 1:右键单击项目并转到属性

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

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

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

步骤4:刷新并清理项目

尤里卡!它正在工作:)

Here's the working solution for this problem:


Step 1: Right click on project and go to properties

Step 2: Go to 'libraries' and remove the project's ' JRE system library'

Step 3: Click on 'Add library'-->'JRE System Library' -->select 'Workspace default JRE'

Step 3: Go to 'Order and Export' and mark the newly added ' JRE system library'

Step 4: Refresh and Clean the project

Eureka! It's working :)

阳光①夏 2024-10-16 09:32:35

我发现解决方案非常非常简单,我认为您应该在修改首选项之前尝试一下。就我而言,我在一个字符串文件中遇到了这个问题,该文件具有基本标签“资源”...我所做的就是从顶部和底部删除标签,清理项目,保存文件并重新插入标签。
此后问题就消失了并且从未给我任何警告。
这听起来可能很简单,但事实上,有时最简单的事情就能解决问题。干杯

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文