验证xhtml11-model-1.xsd时的验证错误

时间:2013-10-29 08:38:06

标签: xml eclipse validation xsd

在生成XML文件时,我使用OMG定义的xsd文件。通过互联网验证需要太长时间。所以,我下载了所有这些文件以进行本地验证。这适用于简单的情况。但是在未来,必须验证更复杂的结构。这包括验证xhtml结构。从http://www.w3.org/MarkUp/SCHEMA下载的大多数xsd文件都存在验证错误。在尝试解决它们时,我集中在文件xhtml11-model-1.xsd上启动,因为该文件包含其他xsd文件使用的许多基本定义。初始下载文件显示71个验证错误!下载的文件没有声明目标名称空间,因此我添加了声明。这样做可以将错误数量减少到4.但此时我陷入困境。我根本没有找到任何纠正剩余错误的方法。我选择其中一个来分析它作为孤立的案例。见下面的代码。可以在文件xhtml-bdo-1.xsd中找到attributeGroup name =“xhtml.dir.attrib”的声明。但是这个文件既没有通过验证,因此我将声明复制到我的测试文件中,以便将所有内容放在一个地方。但是在使用eclipse Kepler验证这个简单的情况时,我在参考xhtml.dir.attrib上得到了以下错误:

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

1 个答案:

答案 0 :(得分:0)

对于您提供的特定代码段,如果您只是确保有一个与您的targetNamespace匹配的默认命名空间(我刚刚在another post在SO上解释了这一点),那么验证错误就会消失。使用“xh11d”为您的XSD处理器提供别名的命名空间(不知何故,通过目录,或通过直接xs:import)。

我会说你不应该忽略验证错误,至少在你做出明智的决定之前不会这样做。

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