没有可用于验证根的匹配全局声明 [英] No matching global declaration available for the validation root

查看:113
本文介绍了没有可用于验证根的匹配全局声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用模式验证XML文档.

Validate an XML document using a schema.

问题的最简单形式显示在两个文件中.

The simplest form of the problem is shown in two files.

<?xml version="1.0"?>

<recipe
  xmlns:r="http://www.namespace.org/recipe">

<r:description>
  <r:title>sugar cookies</r:title>
</r:description>

</recipe>

XSD文档

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema
   version="1.0"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:r="http://www.namespace.org/recipe">

  <xsd:complexType name="recipe">
    <xsd:choice>
      <xsd:element name="description" type="descriptionType"
        minOccurs="1" maxOccurs="1" />
    </xsd:choice>
  </xsd:complexType>

  <xsd:complexType name="descriptionType">
    <xsd:all>
      <xsd:element name="title">
        <xsd:simpleType>
          <xsd:restriction base="xsd:string">
            <xsd:minLength value="5" />
            <xsd:maxLength value="55" />
          </xsd:restriction>
        </xsd:simpleType>
      </xsd:element>
    </xsd:all>
  </xsd:complexType>
</xsd:schema>

错误

来自 xmllint 的完整错误消息:

Error

The full error message from xmllint:

file.xml:4:元素配方:模式有效性错误:元素配方":没有匹配的全局声明可用于验证根.

file.xml:4: element recipe: Schemas validity error : Element 'recipe': No matching global declaration available for the validation root.

问题

什么是正确的语法(或缺少哪些架构属性),以确保可以使用给定的架构来成功验证给定的XML文档?

Question

What is the correct syntax (or what schema attributes are missing) to ensure that the given schema can be used to successfully validate the given XML document?

推荐答案

您需要更改XML实例.您当前的用户说,在名称空间 http:中,有一个名为 description 的类型://www.namespace.org/recipe .但是,在您的XSD定义中,在该命名空间中公开的唯一类型称为 recipe descriptionType .

You need to change your XML instance. Your current one says that there is a type called description in the namespace http://www.namespace.org/recipe. However, in your XSD definition, the only types exposed in that namespace are called recipe and descriptionType.

因此,要么在XSD模式中定义一个称为 description 的类型,要么更改您的实例,以便您正确引用 recipe 类型:

So either define a type called description in the XSD schema, or change your instance so you are referencing the recipe type correctly:

<?xml version="1.0" encoding="utf-8"?>
<r:recipe
  xmlns:r="http://www.namespace.org/recipe">
  <description>
    <title>sugar cookies</title>
  </description>
</r:recipe>

更新这只是解决方案的一半-另一半位于@Aravind的答案中: https://stackoverflow.com/a/8426185/569662

UPDATE This is only half the solution - the other half is in @Aravind's answer here: https://stackoverflow.com/a/8426185/569662

这篇关于没有可用于验证根的匹配全局声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆