Validating XML: No matching global declaration available for the validation root Validating XML: No matching global declaration available for the validation root ruby ruby

Validating XML: No matching global declaration available for the validation root


It's a cryptic error, but it's probably because your XSD is malformed. For example, the contents of the channel, hotel (both the inner and outer elements), room, and request xsd:element tags should all be wrapped in xsd:complexType tags. Also, use is only valid on xsd:attribute, not xsd:element. For elements, use minOccurs and maxOccurs (although both default to 1, so they aren't actually necessary in this case). In addition, your outer hotel element contains a room element, which must contain a hotel element, creating an infinite loop. Further, you don't name your username and password elements properly. Finally, that inner hotel element should probably be date. Here's what I think you're looking for:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">  <!-- channel -->  <xsd:element name="channel">    <xsd:complexType>      <xsd:sequence>        <xsd:element name="username" type="xsd:string"/>        <xsd:element name="password" type="xsd:string"/>      </xsd:sequence>      <xsd:attribute name="name" use="required" type="xsd:string" />    </xsd:complexType>  </xsd:element>  <!-- hotel -->  <xsd:element name="hotel">    <xsd:complexType>      <xsd:sequence>        <xsd:element name="date">          <xsd:complexType>            <xsd:attribute name="from" use="required" type="xsd:string" />            <xsd:attribute name="to" use="required" type="xsd:string" />          </xsd:complexType>        </xsd:element>        <xsd:element ref="room" minOccurs="1"/>      </xsd:sequence>      <xsd:attribute name="id" use="required" type="xsd:string" />    </xsd:complexType>  </xsd:element>  <!-- room -->  <xsd:element name="room">    <xsd:complexType>      <xsd:sequence>        <xsd:element name="allocation" type="xsd:string"></xsd:element>      </xsd:sequence>      <xsd:attribute name="id" use="required" type="xsd:string" />    </xsd:complexType>  </xsd:element>  <!-- building all together -->  <xsd:element name="request">    <xsd:complexType>      <xsd:sequence>        <xsd:element ref="channel" maxOccurs="1"/>        <xsd:element ref="hotel" maxOccurs="1"/>      </xsd:sequence>    <xsd:attribute name="type" use="required" type="xsd:string" />    </xsd:complexType>  </xsd:element></xsd:schema>


Just shooting from the hip here, but have you tried converting the XML::Document holding the schema into an XML::Schema?

http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Schema.html

I don't know that it would make a difference, but it's worth a shot.


I received the same cryptic error message for a different reason.

The first line of my schema file had an unprefixed namespace:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sec.gov/edgar/document/thirteenf/informationtable" xmlns:ns1="http://www.sec.gov/edgar/common" targetNamespace="http://www.sec.gov/edgar/document/thirteenf/informationtable" elementFormDefault="qualified" attributeFormDefault="unqualified">

Note the 'xmlns=' attribute. This placed all the elements declared in the schema into the namespace http://www.sec.gov/edgar/document/thirteenf/informationtable (unless otherwise specified with a namespace prefix). But the XML file that I was trying to validate did not have a matching unprefixed/default namespace:

<informationTable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

So its elements didn't match the schema because they were in "different" namespaces. I hope this is useful to others.