没有为文档检测到语法约束(DTD或XML模式)

我有这个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,我现在得到这个错误:

元素types“模板”的内容必须与“(描述,变体?,变体字段?,允许多重变体?,类模式?,getter-setter?,允许文件扩展名?class?,模板型)”。

在我的情况下,我通过简单地在<?xml ... >标签之后添加<!DOCTYPE xml>来解决这个烦人的警告。

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

这在Eclipse 3.7.1中适用于我:转到Preferences窗口,然后是XML – > XML Files – > Validation。 然后,在右侧的首选项面板的validation文件部分,在下拉框中select“无语法指定”首选项的忽略。 您可能需要closures该文件,然后重新打开,以使警告消失。

(我知道这个问题是旧的,但这是我在search警告时发现的第一个问题,所以我在这里为其他search者发布答案。)

回答:

下面的每个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用于build立一致的数据格式并validation这些数据的接收。 他们定义了一个XML文档的结构,其中包括:

  • 法律要素清单
  • 特殊字符
  • string
  • 还有更多

例如

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

以上线的含义…
第1行)定义为“nameOfYourRootElement”的根元素
第2行)元素定义的开始
第3行)定义为“nameOfYourRootElement1”和“nameOfYourRootElement2”的根元素子元素
第4行)子元素,定义为数据types#PCDATA
第5行)子元素,定义为数据types#PCDATA
第6行)展开&nbsp;实例 到&#xA0; 当文档被XMLparsing器parsing时
第7行)展开&author;实例&author;Your Author Name由XML分析器parsing文档时
第8行)定义结束

真正的解决scheme:

在每个有问题的XML的开始处添加<!DOCTYPE something>

在xml标签之后<?xml version="1.0" encoding="utf-8"?>

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

您是否尝试将模式添加到xml目录?

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

“Window \ preferences \ xml \ xml目录\用户指定的条目”。

点击右侧的“添加”button。


例:

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

作为键types:名称空间名称

至于关键: http : //mycompany.com/hr/schemas


closures并重新打开xml文件并做一些更改来违反模式,您应该被通知

一个新的干净的方式可能是这样写你的XML:

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

上面的作品在Eclipse Juno +中

对我来说这是一个字符编码问题,在Windows上运行eclipse的unix filemode

只是标记完整的代码,切割和粘贴回来(简而言之: CtrlA-CtrlX-CtrlV ),一切都很好 – 没有更多的“没有语法约束…”警告

我无法真正说出为什么得到“无语法限制…”的警告,但是我可以通过彻底删除DOCTYPE声明来激发它。 当我把声明放回来,再次validation,我得到这个错误消息:

元素types“template”的内容必须与“(description +,variation?,variation-field?,allow-multiple-variation?,class-pattern?,getter-setter?,allowed-file-extensions?,template-body + 。

这是正确的,我相信(“所需的类”元素是不允许的)。

这可能是由于在日食中closuresvalidation。

添加DOCTYPE标记…

在这种情况下:

 <!DOCTYPE xml> 

之后添加:

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

所以:

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

我知道这是旧的,但我传递了同样的问题,并在spring的文档中find解决scheme,下面的XMLconfiguration已经解决了我的问题。

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

所以只要尝试使用我的xmlconfiguration的sugested线。

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

  1. 在记事本中复制你的整个代码。
  2. 临时保存文件的任何名称[同时保存文件使用“编码”= UTF-8(或更高,但UTF)]。
  3. closures文件。
  4. 再次打开它。
  5. 复制粘贴回你的代码。

错误必须消失。

这是这个问题的工作解决scheme:


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

第二步:进入“库”,删除项目的“JRE系统库”

第三步:点击“添加库” – >“JRE系统库” – >select“工作区默认JRE”

步骤3:进入“订购与导出”并标记新添加的“JRE系统库”

第4步:刷新和清理项目

find了! 它的工作:)

我发现的解决scheme非常简单,我认为你应该尝试之前修改的偏好。 在我的情况下,我有一个string文件,有一个基地标签“资源”的问题…我所做的只是从顶部和底部删除标签,清理项目,保存文件,并重新插入标签。 这个问题从此消失了,从来没有给我任何警告。 听起来很简单,但是嘿,有时候解决问题是最简单的事情。 干杯