未检测到文档的语法约束(DTD 或 XML 模式)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4551783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No grammar constraints (DTD or XML schema) detected for the document
提问by fastcodejava
I have this dtd : http://fast-code.sourceforge.net/template.dtdBut when I include in an xml I get the warning : No grammar constraints (DTD or XML schema) detected for the document. The xml is :
我有这个 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>
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?,允许文件扩展?,数量-需要-类?,模板主体)”。
回答by Sabuj Hassan
In my case I have solved this annoying warning by simply adding the <!DOCTYPE xml>after the <?xml ... >tag.
在我的情况下,我通过简单地添加标签<!DOCTYPE xml>后解决了这个烦人的警告<?xml ... >。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
回答by Marc Bernstein
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.
这在 Eclipse 3.7.1 中对我有用:转到 Preferences 窗口,然后 XML -> XML Files -> Validation。然后在右侧首选项面板的验证文件部分,在“未指定语法”首选项的下拉框中选择忽略。您可能需要关闭该文件,然后重新打开它以使警告消失。
(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.)
(我知道这个问题很旧,但它是我在搜索警告时发现的第一个问题,所以我在这里为其他搜索者发布了答案。)
回答by Pup
Answer:
回答:
Comments on each piece of your DTD below. Refer to official specfor more info.
下面对您的 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.
>
Simple Explanation:
简单说明:
An extremely basic DTD will look like the second linehere:
一个非常基本的 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. They define the structure of an XML document, including:
DTD 用于建立商定的数据格式并验证此类数据的接收。它们定义了 XML 文档的结构,包括:
- 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 Namewhen document is parsed by XML parser
Line 8) End of definitions
上述行的含义...
第 1 行)定义为“nameOfYourRootElement”的根元素
第 2 行)元素定义的开始
第 3 行)定义为“nameOfYourRootElement1”和“nameOfYourRootElement2”的根元素
子元素 第 4 行)定义为数据的子元素型#PCDATA
线5)子元素,其被定义为数据类型#PCDATA
6行)扩大的情况下 ,以 当文件由XML解析器解析
第7行)扩大的情况下&author;,以Your Author Name当文件由XML解析器解析
的定义第8行)结束
回答by Amir.F
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 写任何东西,但基本上它应该是清单、活动等。据我所知
回答by user1374968
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." i use to add an xsd schema file to the xml catalog under
在 Eclipse 中避免“未检测到文档的语法约束(dtd 或 xml 架构)”。我用来在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 文件并进行一些更改以违反架构,您应该收到通知
回答by Jorge Bastida Cano
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>
回答by Damilola
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+ 中有效
回答by user3022856
For me it was a Problem with character encodingand unix filemoderunning 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),一切都很好 - 不再有“无语法约束...”警告
回答by Bhupendra Kumar
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.
在我的情况下,这导致了其他一些问题。我通过阅读建议解决了这个问题,这又变成了另一个问题,这个问题已经解决了,理解了最初的原因,第一个链接被破坏了(没有找到)。以下是分步图像,解释了为完全解决问题已采取的措施。
回答by mzjn
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:
我真的不能说为什么你会收到“没有语法约束...”警告,但我可以通过完全删除 DOCTYPE 声明在 Eclipse 中引发它。当我放回声明并再次验证时,我收到以下错误消息:
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”元素)。


