Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No matching global declaration available for the validation root

Tags:

xml

xsd

xmllint

Background

Validate an XML document using a schema.

Problem

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

XML Document

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

XSD Document

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

Error

The full error message from xmllint:

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

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?

like image 478
Dave Jarvis Avatar asked Dec 08 '11 04:12

Dave Jarvis


1 Answers

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

like image 177
tom redfern Avatar answered Sep 28 '22 07:09

tom redfern