未找到元素“ ”的声明

2024-01-02

我是使用 XML 和 XSD 文件的新手。我想做的是使用模式验证 xml 文件。这是我的 XML 文件的开头:

<?xml version="1.0" encoding="UTF-8"?>
<movies>
 <doc id="000007">
    <docid>000007</docid>
    <title>#73, Shanthi Nivasa</title>
    <year>2007</year>
    <type>movie</type>
    <colorinfos>
      <colorinfo>Color</colorinfo>
    </colorinfos>
    <genres>
      <genre>Musical</genre>
    </genres>
    <languages>
      <language>Kannada</language>
    </languages>
    <countries>
      <country>India</country>
    </countries>
    <releasedates>
      <releasedate country="India">14 June 2007</releasedate>
    </releasedates>
    <directors>
      <director>Sudeep</director>
    </directors>
    <composers>
      <composer>Bharadwaj (I)</composer>
    </composers>
    <cast>
      <credit>
        <actor>Shivarajkumar</actor>
        <role>Himself</role>
      </credit>
      <credit>
        <actor>Sudeep</actor>
        <role>Raghu</role>
      </credit>
      <credit>
        <actor>Vishnuvardhan (I)</actor>
        <role>Himself</role>
      </credit>
    </cast>
    <plot>#73, Shanthi Nivasa  - the littlest things in life that give peace and happiness in a home. Although #73, Shanthi Nivasa seems to have everything on the surface, it lacks the depth of peace. Amidst the constant family fights, Raghu enters the household as the new cook and brings the ingredient of peace with him. And mysteriously, he leaves. What will #73, Shanthi Nivasa do without Raghu? Will they be able to hold their family together without this unassuming cook's presence?</plot>
    <url>http://localhost:8983/solr/movie.html?000007</url>
  </doc>
</movies>

这是我的架构的开始:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="movies">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="doc" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:short" name="docid"/>
              <xs:element type="xs:string" name="title"/>
              <xs:element type="xs:short" name="year"/>
              <xs:element type="xs:string" name="type"/>
              <xs:element name="colorinfos" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="colorinfo" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="editors" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="editor" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="genres" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="genre" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="keywords" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="keyword" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="languages" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="language" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="soundmixes" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="soundmix"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="countries">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="country" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="certificates" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="certificate" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:string" name="country" use="optional"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="releasedates" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="releasedate" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:string" name="country" use="optional"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="runningtimes" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="runningtime" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:short">
                            <xs:attribute type="xs:string" name="country" use="optional"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="directors" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="director" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="producers" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="producer" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="writers" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="writer" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="composers" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="composer" maxOccurs="unbounded" minOccurs="0"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="othercrew" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="name"/>
                          <xs:element type="xs:string" name="job"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="cast" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="credit" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element type="xs:string" name="actor"/>
                          <xs:element type="xs:string" name="role"/>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element type="xs:string" name="plot"/>
              <xs:element type="xs:anyURI" name="url"/>
            </xs:sequence>
            <xs:attribute type="xs:short" name="id" use="optional"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

每当我尝试验证文件时出现的错误是:

第 2 行第 9 列错误:未找到元素“movies”的声明

该架构是自动生成的(我正在使用 XML 复制编辑器)。 XML 和 XSD 文件的语法也是正确的。


您必须以某种方式将 XSD 与 XML 关联起来。

执行此操作的常见方法是use noNamespaceSchemaLocation对于非命名空间 XML 或schemaLocation对于命名空间 XML https://www.w3.org/TR/xmlschema11-1/#xsi_schemaLocation。要使用此方法,请更改

<movies>

to

<movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="try.xsd">

您还可以使用验证器工具的机制来指定关联,但这些机制往往是特定于实现的,而上述提示往往适用于所有验证器。

See also

  • 如何使用 schemaLocation 或 noNamespaceSchemaLocation 将 XML 链接到 XSD? https://stackoverflow.com/q/35411871/290085
  • 如何正确引用本地XML Schema文件? https://stackoverflow.com/q/19253402/290085
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未找到元素“ ”的声明 的相关文章

随机推荐

  • spring中没有默认构造函数的类的bean类实例化

    我在模型中使用第三方库类 XYZ 作为参数 XYZ 没有默认构造函数 所以 spring 无法为其创建 bean 给出错误消息 org springframework web util NestedServletException Requ
  • 在满足特定条件之前“阻止”的最佳方法

    我想创建一些以通用方式使用的方法 它会阻塞 除非某个超时到期 直到满足给定条件 代码中的用法类似于 WaitUntil condition 我尝试使用 While 循环来实现它 但这似乎是一种浪费 在当前的实现中 我正在初始化一个 一次性
  • 在 ios swift 中实施 Google Analytics

    我正在遵循 Analytics for iOS developers google com analytics devguides collection ios v3 ver swift 指南 但我的 Swift 代码项目中出现了无法修复的
  • 使用 imap 和 php 检索最近 3 封电子邮件

    我试图弄清楚如何使用 imap 和 php 获取最新的 3 封电子邮件 已看到和未看到 由于邮箱内有 1 000 封电子邮件 因此需要节约资源 我认为获取所有标头可能需要太多资源 我只需要发件人 主题和日期 任何想法 感谢您的任何建议 帮助
  • iPhone 上的日期字符串中的毫秒数应使用什么格式字符串?

    我需要解析包含毫秒的格式的字符串 我应该使用什么格式字符串来获取正确的日期值 例如 假设我有一个具有以下值的字符串 2011 06 23T13 13 00 000 在以下代码中我应将什么格式字符串传递给 NSDateFormatter NS
  • VB.NET 中标识符两边的方括号代表什么?

    一般来说 我对 VB 和 NET 非常熟悉 但我刚刚遇到了这段代码 Me GetType 周围括号的用途是什么GetType 方括号用于告诉编译器应该将其解释为类型 即使它是关键字 但你的例子应该是一样的Me GetType 例如 您可以将
  • 良好的 DRY 方法来渲染和 AJAX 更新页面

    想象一下一个评论网站 用户可以在其中输入评级和可选的简短评论 在每个评论页面上 您都会收到许多评论 这些评论显示在页面末尾的表格中 顺便说一句 不寻找数据网格类型控件 太简单了 我想让用户输入新评论并更新页面而无需刷新页面 到目前为止都是简
  • MEF 和 ASP.NET MVC

    我想将 MEF 与 asp net mvc 一起使用 我写了以下控制器工厂 public class MefControllerFactory DefaultControllerFactory private CompositionCont
  • 如何检测在CustomList中单击了哪个按钮以及在哪个位置

    我正在使用自定义列表视图 其中每个项目都有两个按钮 以下是我的项目 xml
  • 导出 JSON 数据并加载到关系数据库中

    是否有将 JSON 数据转换为具有多个表的关系数据库的标准方法 我们需要从 MongoDB 实例导出数据并将其导入 Redshift 集群 唯一的问题是一些 MongoDB 字段包含对象和数组 Redshift 集群接受 CSV 因此我认为
  • 从登录页面删除导航菜单

    有基本的 html admin layout html 我写的 div div div div 有兴趣知道如何从登录页面删除管理导航 尝试设置变量隐藏菜单登录控件并用 ng if hide menu 隐藏它 但这对我不起作用 它隐藏所有管理
  • Appium 错误 Xcode 找不到与“com.facebook.WebDriverAgentRunner”匹配的配置文件

    我在真实 iOS 设备上执行自动化时遇到问题 系统配置 应用程序1 6 0 设备 iPhone 5c ios 10 1 代码8 2 例外是 Xcode Testing failed No profiles for com facebook
  • Chrome 控制台日志看不到 AJAX post/get 请求/响应

    我不知道它是否来自 Chrome 最近的更新之一 我不知道它是否是我在不知不觉中设法关闭的选项 但无论哪种方式 在过去几天的某个时候 我在 Chrome 上的控制台日志停止显示发布 获取请求 因此我可以看到正在发布的内容以及发回的响应内容
  • 多个RecyclerView同步滚动

    我有一个 ViewPager 每页显示一个片段 该片段包含 RecyclerView 内的项目列表 项目列表始终具有相同的大小 并且项目的视图也具有相同的高度 当滚动其中一个 RecyclerView 时 我希望其他 RecyclerVie
  • 如何调用函数的 AWS Lambda 权限列表

    要允许 AWS 服务调用 lambda 函数 您需要应用权限 这json对于此权限可能看起来有点像这样 FunctionName someFunction StatementId 1 Action lambda InvokeFunction
  • 使用 CSS 更改 SVG spritesheet sprite 的颜色

    我使用 SVG spritesheet 作为图标 我想对 hover active 进行颜色更改 我发现 更改 SVG 颜色的唯一方法是 SVG 数据是否内联 有一个很好的脚本可以将外部 svg 转换为内联 SVG 代码 如何使用 CSS
  • PHP:如何在foreach循环内移动数组指针?

    animals array cat dog horse elephant foreach animals as animal var dump animal next animals 上面的代码输出 cat dog horse elepha
  • Phonegap 数据库错误

    我正在尝试为我的电话间隙应用程序建立一个数据库 问题是除了设置表的事务之外的所有事务都会产生错误 SQLTransactionCallback 为空或引发异常 这是代码 function Datasetup db window openDa
  • 登录控制器中覆盖的经过身份验证的方法不起作用

    我试图覆盖登录控制器中的经过身份验证的方法 但不知何故它不起作用 我只是尝试简单地 dd 但仍然不起作用 下面是我的功能代码 public function authenticated Request request user dd hi
  • 未找到元素“ ”的声明

    我是使用 XML 和 XSD 文件的新手 我想做的是使用模式验证 xml 文件 这是我的 XML 文件的开头