简体   繁体   English

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

[英]No grammar constraints (DTD or XML schema) detected for the document

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.我有这个 dtd: http : //fast-code.sourceforge.net/template.dtd但是当我包含在 xml 中时,我收到警告:没有检测到文档的语法约束(DTD 或 XML 架构)。 The xml is : 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>

EDIT : I changed the xml, I am getting this error now:编辑:我更改了 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)".元素类型“模板”的内容必须匹配“(描述,变体?,变体-字段?,允许-多重变体?,类模式?,getter-setter?,允许文件扩展?,数量-需要-类?,模板主体)”。

In my case I have solved this annoying warning by simply adding the <!DOCTYPE xml> after the <?xml ... > tag.就我而言,我通过在<?xml ... >标签之后添加<!DOCTYPE xml>解决了这个烦人的警告。

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

This worked for me in Eclipse 3.7.1: Go to the Preferences window, then XML -> XML Files -> Validation.这在 Eclipse 3.7.1 中对我有用:转到 Preferences 窗口,然后 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.您可能需要关闭该文件,然后重新打开它以使警告消失。

(I know this question is old but it was the first one I found when searching on the warning, so I'm posting the answer here for other searchers.) (我知道这个问题很旧,但它是我在搜索警告时发现的第一个问题,所以我在这里为其他搜索者发布了答案。)

Answer:回答:

Comments on each piece of your DTD below.下面对您的 DTD 的每一部分进行评论。 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:一个非常基本的 DTD 看起来像这里的第二行

<?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. DTD 用于建立商定的数据格式并验证此类数据的接收。 They define the structure of an XML document, including:它们定义了 XML 文档的结构,包括:

  • a list of legal elements法律要素清单
  • special characters特殊字符
  • character strings字符串
  • and a lot more还有更多

Eg例如

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

Meaning of above lines...上面几行的意思...
Line 1) Root element defined as "nameOfYourRootElement"第 1 行)定义为“nameOfYourRootElement”的根元素
Line 2) Start of element definitions第 2 行)元素定义的开始
Line 3) Root element children defined as "nameOfYourRootElement1" and "nameOfYourRootElement2"第 3 行)定义为“nameOfYourRootElement1”和“nameOfYourRootElement2”的根元素子元素
Line 4) Child element, which is defined as data type #PCDATA第 4 行)子元素,定义为数据类型#PCDATA
Line 5) Child element, which is defined as data type #PCDATA第 5 行)子元素,定义为数据类型#PCDATA
Line 6) Expand instances of &nbsp;第 6 行)展开&nbsp;实例to &#xA0;&#xA0; when document is parsed by XML parser当 XML 解析器解析文档时
Line 7) Expand instances of &author;第 7 行)展开&author;实例to Your Author Name when document is parsed by XML parser XML 解析器解析文档时显示为Your Author Name
Line 8) End of definitions第 8 行)定义结束

The Real Solution:真正的解决方案:

add <!DOCTYPE something> to the begining of each problematic XML,<!DOCTYPE something>添加到每个有问题的 XML 的开头,

after the xml tag <?xml version="1.0" encoding="utf-8"?>在 xml 标签<?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你可以为 doctype 写任何东西,但基本上它应该是清单、活动等。据我所知

Have you tried to add a schema to xml catalog?您是否尝试将架构添加到 xml 目录?

in eclipse to avoid the "no grammar constraints (dtd or xml schema) detected for the document."在 Eclipse 中避免“未检测到文档的语法约束(dtd 或 xml 架构)”。 i use to add an xsd schema file to the xml catalog under我用来在xml目录下添加一个xsd架构文件

"Window \\ preferences \\ xml \\ xml catalog \\ User specified entries". “窗口\\首选项\\xml\\xml 目录\\用户指定的条目”。

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从这个xml我生成并保存了一个xsd:/home/my_user/xsd/my_xsd.xsd

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

As key type: Namespace name作为键类型:命名空间名称

As key: http://mycompany.com/hr/schemas作为关键: http : //mycompany.com/hr/schemas


Close and reopen the xml file and do some changes to violate the schema, you should be notified关闭并重新打开 xml 文件并进行一些更改以违反架构,您应该收到通知

Add DOCTYPE tag ...添加 DOCTYPE 标签...

In this case:在这种情况下:

<!DOCTYPE xml>

Add after:之后添加:

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

So:所以:

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

A new clean way might be to write your xml like so:一种新的干净方法可能是像这样编写你的 xml:

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

<rootElement>
 ....
</rootElement>

The above works in Eclipse Juno+以上在 Eclipse Juno+ 中有效

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.以下是分步图像,解释了为完全解决问题已采取的措施。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

For me it was a Problem with character encoding and unix filemode running eclipse on Windows:对我来说,在 Windows 上运行 eclipse 的字符编码unix 文件模式存在问题:

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只需标记完整的代码,将其剪切并粘贴回(简而言之: CtrlA-CtrlX-CtrlV ),一切都很好 - 不再有“无语法约束...”警告

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.我真的不能说为什么你会收到“没有语法约束...”警告,但我可以通过完全删除 DOCTYPE 声明在 Eclipse 中引发它。 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+).元素类型“模板”的内容必须匹配“(描述+,变体?,变体字段?,允许多变体?,类模式?,getter-setter?,允许文件扩展?,模板正文+) .

And that is correct, I believe (the "number-required-classes" element is not allowed).我相信这是正确的(不允许使用“number-required-classes”元素)。

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.我知道这是旧的,但我通过了同样的问题,并在 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">

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.所以只需尝试使用我的 xml 配置的 sugested 行。

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

  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)].使用任何名称临时保存文件[保存文件时使用“编码”= UTF-8(或更高但UTF)]。
  3. close the file.关闭文件。
  4. open it again.再次打开它。
  5. copy paste it back on your code.将其复制粘贴回您的代码。

error must be gone.错误必须消失。

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

Validation works and the warning is fixed (not ignored).验证有效并且警告已修复(未被忽略)。

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

I too had the same problem in eclipse using web.xml file我在使用 web.xml 文件的 eclipse 中也遇到了同样的问题
it showed me this " no grammar constraints referenced in the document "它向我展示了“文档中没有引用的语法约束”

but it can be resolved by adding tag但可以通过添加标签来解决
after the xml tag ie <?xml version = "1.0" encoding = "UTF-8"?>在 xml 标签之后,即<?xml version = "1.0" encoding = "UTF-8"?>

Solved this issue in Eclipse 3.5.2.在 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.关闭所有选项卡,重新打开时警告消失了。

Here's the working solution for this problem:这是此问题的有效解决方案:


Step 1: Right click on project and go to properties步骤1:右键单击项目并转到属性

Step 2: Go to 'libraries' and remove the project's ' JRE system library'第 2 步:转到“库”并删除项目的“JRE 系统库”

Step 3: Click on 'Add library'-->'JRE System Library' -->select 'Workspace default JRE'第三步:点击'Add library'-->'JRE System Library'-->选择'Workspace default JRE'

Step 3: Go to 'Order and Export' and mark the newly added ' JRE system library'步骤3:进入'Order and Export'并标记新添加的'JRE系统库'

Step 4: Refresh and Clean the project第 4 步:刷新并清理项目

Eureka!尤里卡! It's working :)它的工作:)

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干杯

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.我有这个dtd: http : //fast-code.sourceforge.net/template.dtd但是当我包含在xml中时,我得到了警告:没有为文档检测到语法约束(DTD或XML模式)。 The xml is : 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>

EDIT : I changed the xml, I am getting this error now:编辑:我更改了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)".元素类型“模板”的内容必须匹配“(描述,变量?,变量字段?,允许多变量?,类模式?,getter-setter ?、允许文件扩展名?,所需数字?类?,模板主体)”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有为文档检测到语法约束(DTD或XML模式)6 - No grammar constraints (DTD or XML schema) detected for the document 6 未检测到文档的语法约束(DTD或XML架构) - No grammar constraints (DTD or XML schema) detected for the document 没有为给定文档检测到语法约束(DTD或XML模式) - No grammar constraints (DTD or XML schema) detected for the given document 未检测到文档的语法约束(DTD或XML架构)(Android) - No grammar constraints (DTD or XML schema) detected for the document (Android) 错误:文档中未引用语法约束(DTD或XML架构) - Error: No grammar constraints (DTD or XML Schema) referenced in the document 指定模式时,Eclipse产生错误“文档中未引用语法约束(DTD或XML模式)” - Eclipse producing error “No grammar constraints (DTD or XML Schema) referenced in the document” when Schema is specified 我该如何解决“文档中没有引用语法限制(DTD或XML模式)”的警告。 - how can i solve “No grammar constraints (DTD or XML Schema) referenced in the document.” WARNING Eclipse抱怨“尽管在文档中没有指定语法约束(DTD或XML模式)” - Eclipse complains about “No grammar constraint (DTD or XML Schema) referenced in the document” despite one being specified XML 文档是否可以同时遵循 DTD 和 XML 模式? - Can an XML document follow both a DTD and an XML Schema? 使用XML Schema,DTD,RelaxNG和Schematron验证DocBook文档 - Validate DocBook document using XML Schema, DTD, RelaxNG and Schematron
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM