2013-10-29 60 views
1

在生成XML文件时,我使用由OMG定义的xsd文件。通过互联网验证需要太长时间。所以,我下载了所有这些文件进行本地验证。这适用于简单的情况。但是在继续前进时,必须验证更复杂的结构。这包括验证xhtml结构。大多数从http://www.w3.org/MarkUp/SCHEMA下载的xsd文件都有验证错误。在试图解决它们时,我将注意力集中在文件xhtml11-model-1.xsd上,因为这个文件包含了很多其他xsd文件使用的基本定义。最初的下载文件显示71个验证错误!下载的文件没有声明目标名称空间,因此我添加了声明。这样做可以将错误的数量减少到4个。但是在这一点上,我陷入了困境。我根本没有发现任何意思来纠正其余的错误。我挑出其中一个来分析它作为孤立的案例。见下面的代码。 attributeGroup name =“xhtml.dir.attrib”的声明可以在文件xhtml-bdo-1.xsd中找到。但是这个文件没有通过验证,因此我将声明复制到我的测试文件中,以便将所有文件放在一个地方。但在确认与日食开普勒这个简单的例子,我得到的错误如下的裁判xhtml.dir.attrib:在验证xhtml11-model-1.xsd时出现验证错误

<xs:attributeGroup ref="xhtml.dir.attrib" /> 
s4s-elt-must-match.1: The content of 'xhtml.I18n.extra.attrib' must match (annotation?, ((attribute | attributeGroup)*, anyAttribute?)). A problem was found starting at: attributeGroup. 

什么是错的?为什么在声明显示正确时引用声明了错误。这是eclipse验证器的问题吗?我的误解?我应该忽略这些验证错误吗?为什么从w3.org下载的xsd文件没有targetNamespace声明,因为它似乎需要验证和使用这些文件? 感谢您的任何提示。

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.w3.org/1999/xhtml/datatypes/" 
xmlns:xh11d="http://www.w3.org/1999/xhtml/datatypes/" 
elementFormDefault="qualified" > 

<xs:attributeGroup name="xhtml.dir.attrib"> 
    <xs:annotation> 
     <xs:documentation> 
      "dir" Attribute from Bi Directional Text (bdo) Module 
     </xs:documentation> 
    </xs:annotation> 
    <xs:attribute name="dir"> 
     <xs:simpleType> 
      <xs:restriction base="xs:NMTOKEN"> 
       <xs:enumeration value="ltr" /> 
       <xs:enumeration value="rtl" /> 
      </xs:restriction> 
     </xs:simpleType> 
    </xs:attribute> 
</xs:attributeGroup> 

<xs:attributeGroup name="xhtml.I18n.extra.attrib"> 
    <xs:annotation> 
     <xs:documentation>Extended I18n attribute</xs:documentation> 
    </xs:annotation> 
    <xs:attributeGroup ref="xhtml.dir.attrib" /> 
    <xs:attribute name="lang" type="xh11d:LanguageCode" /> 
</xs:attributeGroup> 
</xs:schema> 

回答

0

对于您所提供的特定片段中,验证错误消失,如果你只是确保有一个默认的命名空间,你的目标名称(我刚刚在another post上如此解释这个在这里),你匹配使XSD处理器可以使用“xh11d”命名空间(不管怎样,通过目录或直接通过xs:import)。

我会说你不应该忽略验证错误,至少不能直到你做出明智的决定。

我会下载XSD,我会自己看看;如果有什么值得的话,我会在这里告诉你。

+0

在我的代码片段添加默认名称空间的错误消失了。到目前为止,提示是正确的。修改为: \t \t 但是这并未” t真的有帮助他原来的xsd和问题是,为什么我应该修改w3站点的xsd? – juerg

+0

我想这些文件是公开的,已经过彻底测试,为什么他们在w3网站工作,但不在本地?此外,我观察到循环依赖,这实际上没有帮助!你如何处理这种情况? – juerg

+0

我个人认为这些文件已经过彻底测试。至少基于可用的工具(基于.NET和Java),某些XSD无效。 (我仍在研究它...例如,我得到一个cvc-enumeration-aria-attributes-1.xsd文件中'aria-related'属性的默认值无效...)循环依赖性很差在包装方面...但它不应该是一个问题......如果您删除所有架构位置并手动将所有文件放在模式集合中......循环依赖关系消失,而内容仍然正确...... –