【问题标题】:ERROR: Cannot find the declaration of element 'xs:schema'错误:找不到元素“xs:schema”的声明
【发布时间】:2016-03-10 17:30:30
【问题描述】:

我目前使用的 XML 存在问题。

错误:Ln 152 Col 13 - cvc-complex-type.2.4.b:元素的内容 “程序”不完整。需要“{program}”之一。 1 个错误(已解决)

错误:cvc-elt.l:找不到元素“xs:schema”的声明。

我想知道是否有其他人遇到过这个错误并找到了解决方法,谢谢。

编辑:我不得不编辑帖子,因为我使用的是同一个文件,当我发布 xml 和 xsd 文件时,它让其中一位成员感到困惑。我想我应该只发布我遇到问题的文件,还在学习,抱歉。

XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="CBC_programs">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="programs" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="programs">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Business_Programs" />
            <xs:element name="Law_Programs_in_Ontario" />
            <xs:element name="Information_Technology_Programs" />
            <xs:element name="Engineering_Programs" />
            <xs:element name="Marketing_Programs" />
            <xs:element name="Health_Administration_Programs" />
            <xs:element name="Community_Service_and_Child_Care_Programs" />
        
        <xs:element ref="program" minOccurs="1" maxOccurs="unbounded" />

        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="program">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="name" />
            <xs:element name="length" />
            <xs:element name="tuition" />
            <xs:element name="description" />
        </xs:sequence>
        <xs:attribute name="program_id" type="xs:string"/>
    </xs:complexType>
</xs:element>

</xs:schema>

【问题讨论】:

  • 您希望更改您的 XSD 以匹配您的 XML,反之亦然?
  • 没有;我想弄清楚是什么导致了错误,但我发现我正在引用程序而不是仅仅声明它。此错误已解决。第二个错误是 cvc-elt.l: Cannot find the declaration of element 'xs:schema'。我仍在努力弄清楚。
  • 您可以通过更改 XML 或更改 XSD(或两者兼而有之,技术上)来修复错误。你想改变哪个?
  • XSD 是我唯一尝试使用的唯一,(xsd 需要更改。)我正在更新我的主题,以了解我最近解决的错误,以及我想要解决的问题修复。
  • stackoverflow.com/questions/7348353/… 的可能重复项——您在使用什么验证器,在什么环境中工作?

标签: xml xsd


【解决方案1】:

您的架构有几件事:

  1. 您没有为它定义命名空间
  2. 在您的复杂类型定义中,您声明了元素,但没有声明它们的类型(这是您遇到的错误......它无法确定程序的类型),例如
<xs:element name="description" type="xs:string"/>
  1. 在“程序”中使用序列加元素 ref 看起来有点奇怪,您确定这是您想要实现的吗?

http://www.w3schools.com/xml/schema_intro.asp 有一个很好的模式教程,如果你想让我扩展答案,请添加评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    相关资源
    最近更新 更多