No matching global declaration available for the validation root

前端 未结 3 1344
春和景丽
春和景丽 2020-12-25 09:44

Background

Validate an XML document using a schema.

Problem

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

XML Document

<
相关标签:
3条回答
  • 2020-12-25 10:11

    In my practice, I got the No matching global declaration available for the validation root in two cases:

    • If XSD does not contain an <xsd:element name="recipe" .../> explained in @aravind-r-yarram's answer.
    • If <recipe/> in XML does not contain an xmlns attribute. In such case adding the xmlns will help:

      <recipe xmlns="http://www.namespace.org/recipe">
          ...
      </recipe>
      
    0 讨论(0)
  • 2020-12-25 10:12

    Only global element definitions can be used as root elements. Your schema only has complex types and hence the error. Change the <xsd:complexType name="recipe"> to

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

    Read more about this here

    0 讨论(0)
  • 2020-12-25 10:21

    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.

    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>
    

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

    0 讨论(0)
提交回复
热议问题