JAXB unmarshal validation throws cvc-elt.1: Cannot find the declaration of element error - validation

I'm kind of new to JAXB and validation, and have spent several hours trying to figure out this problem to no avail. I've created a simple JAXB unmarshaller sample to parse an XML file. I have created an appropriate XSD file as well, but the validator keeps complaining that it is unable to find the declaration of an element.
I think it may be related to namespace issues, but I've tried everything I can think of and still can't seem to resolve the error. As far as I can tell, my XSD and XML are proper, so it may have to do with the way I am instantiating the unmarshaller, but I can't seem to find the problem anywhere.
The error/exception I keep getting is:
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'calculateBorrowingDataResponse'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:85)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:47)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:113)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:236)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:119)
at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:102)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:299)
... 2 more
Here are the source files that are causing the error.
Java Code:
// We need a Document
InputStream is = UnmarshalTest.class.getClassLoader().getResourceAsStream("calculateBorrowingDataResponse.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Node node = db.parse(is);
// Creating an unmarshaller
Unmarshaller u = JAXBContext.newInstance(CalculateBorrowingDataResponseType.class).createUnmarshaller();
// Setting the Validation
Schema schema;
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = schemaFactory.newSchema(new File("src/main/webapp/WEB-INF/wsdl/CalculateBorrowingDataResponse.xsd"));
u.setSchema(schema);
u.unmarshal(node, CalculateBorrowingDataResponseType.class);
CalculateBorrowingDataResponse.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
version="1.1"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse"
xmlns:lssSt="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse"
xmlns:cbdRes="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- CalculateBorrowingData -->
<xsd:complexType name="CalculateBorrowingDataResponseType">
<xsd:sequence>
<xsd:element name="loanAgmt" type="cbdRes:LoanAgreementType" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="LoanAgreementType">
<xsd:sequence>
<xsd:element name="borrowingBasedPmtAmt" type="lssSt:borrowingBasedPmtAmt" minOccurs="0" maxOccurs="1" />
<xsd:element name="maxPmtAmt" type="lssSt:maxPmtAmt" minOccurs="0" maxOccurs="1" />
<xsd:element name="borrowingCapacityMin" type="lssSt:borrowingCapacityMin" minOccurs="0" maxOccurs="1" />
<xsd:element name="borrowingCapacityMax" type="lssSt:borrowingCapacityMax" minOccurs="0" maxOccurs="1" />
<xsd:element name="propertyValueMinAmt" type="lssSt:propertyValueMinAmt" minOccurs="0" maxOccurs="1" />
<xsd:element name="propertyValueMaxAmt" type="lssSt:propertyValueMaxAmt" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="calculateBorrowingDataResponse" type="cbdRes:CalculateBorrowingDataResponseType"/>
<xsd:simpleType name="borrowingBasedPmtAmt">
<xsd:restriction base="xsd:decimal" >
<xsd:totalDigits value="19" />
<xsd:fractionDigits value="4" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="maxPmtAmt">
<xsd:restriction base="xsd:decimal" >
<xsd:totalDigits value="19" />
<xsd:fractionDigits value="4" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="borrowingCapacityMin">
<xsd:restriction base="xsd:decimal" >
<xsd:totalDigits value="19" />
<xsd:fractionDigits value="4" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="borrowingCapacityMax">
<xsd:restriction base="xsd:decimal" >
<xsd:totalDigits value="19" />
<xsd:fractionDigits value="4" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="propertyValueMinAmt">
<xsd:restriction base="xsd:decimal" >
<xsd:totalDigits value="19" />
<xsd:fractionDigits value="4" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="propertyValueMaxAmt">
<xsd:restriction base="xsd:decimal" >
<xsd:totalDigits value="19" />
<xsd:fractionDigits value="4" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
calculateBorrowingDataResponse.xml
<?xml version="1.0" encoding="UTF-8"?>
<calculateBorrowingDataResponse
xmlns="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://www.domain.com/ClientServices/LendingSimulation/V1.1">
<loanAgmt>
<borrowingBasedPmtAmt>1231231</borrowingBasedPmtAmt>
<maxPmtAmt>987654321</maxPmtAmt>
<borrowingCapacityMax>99999</borrowingCapacityMax>
</loanAgmt>
</calculateBorrowingDataResponse>
I tried both with and without the last element definition in the XSD (ie: xsd:element name="calculateBorrowingDataResponse" ... ) but neither work.
I'm running out of ideas of different things to try. Any suggestions or recommendations would be greatly appreciated!

This is the fourth hour that I'm trying to find the source of the problem. After much struggle, now, I'm confident that you're missing a single line of code to be able to rise to glorious heights!
The problem is that DocumentBuilderFactory created via DocumentBuilderFactory.newInstance() by default isn't namespace aware—yeah.
You can overcome this in two ways:
make your DocumentBuilderFactory namespace aware:
DocumentBuilderFactory.setNamespaceAware(true);
or use a StreamSource while unmarshalling and drop the DocumentBuilder and his little friends altogether:
Unmarshaller.unmarshal(StreamSource, Class<T>);
In case of the second choice you're to do it like this.
InputStream xsdStream = ...
InputStream xmlStream = ...
SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema s = schemaFactory.newSchema(xsdStream);
JAXBContext c = JAXBContext.newInstance(CalculateBorrowingDataResponseType.class);
Unmarshaller u = c.createUnmarshaller();
u.setSchema(schema);
CalculateBorrowingDataResponseType b =
u.unmarshal(new StreamSource(xmlStream), CalculateBorrowingDataResponseType.class);
By the way, on this schema-awareness-ness-document-builderness-awesomeness there is a lot info in the top section of the Unmarshaller class' documentation, you should definitely check that out!

Related

CURL command line with parameters

Maybe thats a stupid question, but I am stopped because of this. I have the WSDL structure that is the following as the image:
<wsdl:types>
<xsd:schema attributeFormDefault="qualified" targetNamespace="urn:sap-com:document:sap:rfc:functions">
<xsd:simpleType name="char10">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char17">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="17"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char5">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="5"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="char6">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="6"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="string">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:complexType name="AUTH">
<xsd:sequence>
<xsd:element name="TIPO" type="tns:char6"/>
<xsd:element name="USERNAME" type="tns:char10"/>
<xsd:element name="PASSWORD" type="tns:char10"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ASK">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="AUTHENTICATION" type="tns:AUTH"/>
<xsd:element name="REQUEST_NUMBER_IN" type="tns:char17"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="MY_RESP">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="PENDING" type="tns:string"/>
<xsd:element name="PHOTO" type="tns:string"/>
<xsd:element name="REQUEST_NUMBER_OUT" type="tns:char17"/>
<xsd:element name="STATUS" type="tns:char5"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
It is a must doing this first connection with curl in cmd (dont ask me why)
The command I am trying is:
curl "http://URL?username=user&password=pwd&tipo=0" --data #file.wsdl
But I get a message from the server that the login is wrong. What I want to ask is, am I filling the parameters correct?
There is a chance that your password may contain non-alphabetic characters and your shell is interpreting them accordingly to its special function instead of just reading your input as a simple, shell meaningless string. If that is the case, try to escape them and check if that is your issue.

undefined complextype is used as a base for complex type extension

What is the problem in my WSDL file? The Visual Studio complains about an undefined complex type.
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns1="http://osmc.synium.com/services/presence" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns2="http://types.osqq.syqq.com" xmlns:impl="com.syqq.osqq.services.presence" xmlns:intf="com.syqq.osqq.services.presence" targetNamespace="com.syqq.osqq.services.presence" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://types.osqq.syqq.com">
<xsd:import namespace="http://osqq.syqq.com/services/presence" />
<xsd:import namespace="com.syqq.osqq.services.presence" />
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:complexType name="SoapBinaryMessage" abstract="true">
<xsd:sequence>
<xsd:element name="data64" nillable="true" type="xsd:string" />
<xsd:element name="version" nillable="true" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://osmc.synium.com/services/presence">
<xsd:import namespace="com.syqq.osqq.services.presence" />
<xsd:import namespace="http://types.osqq.syqq.com" />
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:complexType name="PresenceStatusBinary">
<xsd:complexContent mixed="false">
<xsd:extension base="tns2:SoapBinaryMessage">
<xsd:sequence />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
...
</wsdl:types>
Any ideas?
The problem occurs in line xsd:extension base="tns2:SoapBinaryMessage
You're missing the prefix declaration for tns2; this needs to be added somewhere such that it'll be in scope for the <xsd:extension base="tns2:SoapBinaryMessage"> node (the best place as far as I am concerned might be the second xsd:schema declaration):
xmlns:tns2="http://types.osqq.syqq.com"

xsd validation in CodeIgniter

I am using CodeIgniter, and I want to validate xml with below xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:simpleType name="non_empty_string">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="xml">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item">
<xsd:simpleType>
<xsd:union memberTypes="non_empty_string xsd:integer"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
when I am trying to validate xml against this xsd, only first member type is getting validated (non_empty_string ), not the second one, any guess why this is happening. Thank you.
You can use XMLReader to validate your XML against xsd file.
refer this link for more information
http://de.php.net/manual/en/xmlreader.setschema.php

Why won't this Schema validate this XML file?

The XML file:
<Lista count="3">
<Pelicula nombre="Jurasic Park 3">
<Genero>Drama</Genero>
<Director sexo="M">Esteven Spielberg</Director>
<Temporada>
<Anho>2002</Anho>
<Semestre>Verano</Semestre>
</Temporada>
</Pelicula>
<Pelicula nombre="Maldiciones">
<Genero>Ficcion</Genero>
<Director sexo="M">Pedro Almodovar</Director>
<Temporada>
<Anho>2002</Anho>
<Semestre>Verano</Semestre>
</Temporada>
</Pelicula>
<Pelicula nombre="Amor en New York">
<Genero>Romance</Genero>
<Director sexo="F">Katia Hertz</Director>
<Temporada>
<Anho>2002</Anho>
<Semestre>Verano</Semestre>
</Temporada>
</Pelicula>
</Lista>
And here's the XML Schema file I made, it's not working. :\
<xsd:complexType name="Lista">
<xsd:attribute name="count" type="xsd:integer" />
<xsd:complexContent>
<xsd:element name="Pelicula" type="xsd:string">
<xsd:attribute name="nombre" type="xsd:string" />
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Genero" type="generoType"/>
<xsd:element name="Director" type="directorType">
<xsd:attribute name="sexo" type="sexoType"/>
</xsd:element>
</xsd:element name="Temporada">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Anho" type="anhoType" />
<xsd:element name="Semestre" type="semestreType" />
</xsd:sequence>
</xsd:complexType>
<xsd:element></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:complexContent>
</xsd:complexType>
<xsd:simpleType name="sexoType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="F"/>
<xsd:enumeration value="M"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="directorType">
<xsd:restriction base="xsd:string" />
</xsd:simpleType>
<xsd:simpleType name="generoType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Drama"/>
<xsd:enumeration value="Accion"/>
<xsd:enumeration value="Romance"/>
<xsd:enumeration value="Ficcion"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="semestreType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Verano"/>
<xsd:enumeration value="Invierno"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="anhoType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1970"/>
<xsd:maxInclusive value="2020"/>
</xsd:restriction>
</xsd:simpleType>
Try declaring and using your types separately. This makes the XSD a bit longer, but less nested and more readable (and more reusable, too):
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- document element -->
<xs:element name="Lista" type="listaType" />
<!-- type definitions -->
<xs:complexType name="listaType">
<xs:sequence>
<xs:element name="Pelicula" type="peliculaType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="count" type="countType" />
</xs:complexType>
<xs:complexType name="peliculaType">
<xs:all>
<xs:element name="Genero" type="generoType" />
<xs:element name="Director" type="directorType" />
<xs:element name="Temporada" type="temporadaType" />
</xs:all>
<xs:attribute name="nombre" type="xs:string" />
</xs:complexType>
<xs:complexType name="directorType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="sexo" type="sexoType" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="temporadaType">
<xs:all>
<xs:element name="Anho" type="anhoType" />
<xs:element name="Semestre" type="semestreType" />
</xs:all>
</xs:complexType>
<xs:simpleType name="sexoType">
<xs:restriction base="xs:string">
<xs:enumeration value="F" />
<xs:enumeration value="M" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="generoType">
<xs:restriction base="xs:string">
<xs:enumeration value="Drama" />
<xs:enumeration value="Accion" />
<xs:enumeration value="Romance" />
<xs:enumeration value="Ficcion" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="semestreType">
<xs:restriction base="xs:string">
<xs:enumeration value="Verano" />
<xs:enumeration value="Invierno" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="anhoType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1970" />
<xs:maxInclusive value="2020" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="countType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
The above validates your input XML.
Note that:
The convention for the XML Schema namespace prefix is xs (AFAIK - you can still go on and use xsd if you prefer).
The count attribute is really unnecessary, since the count can a) easily be calculated and b) there is a risk of something going wrong when the count attribute value and the actual count differ for some reason. Things that are derivable from the data should never be part of the data.
Oh, and to answer your initial question (why does mine not work):
You never declare an actual document element ("Lista"), you just declare its type. Compare with my solution.
In the complexType name="Lista":
attribute cannot be the first child of a complex type. Attributes must be declared after everything else.
complexContent cannot contain element.
in fact, you don't need a complexContent at all - just use a sequence instead.
In element name="Pelicula":
The type attribute is illegal when you declare a complexType within.
In the complexType for "Pelicula":
Again, attributes last.
Don't use a sequence unless you want to make any other order of children illegal. In this type of document I would guess child order is irrelevant.
In element name="Director":
You can't declare any attributes since when you already declared a type. Include the sexo attribute in the directorType
In simpleType name="directorType":
This should in reality be a complexType containing simpleContent with an extension. This way you can include the sexo attribute
Your XSD isn't even well formed XML.
Your XML iswas not well-formed, either. I have fixed it to be able to test in the first place.
P.S.: There is enough XSD documentation freely available to fix many of the basic problems you've had. There are XSD validators on the Net that help you by telling you what constructs are illegal. Knowing everything is absolutely not necessary, but a little reading + trial and error would have helped. ;-)
For a start:
<Semestre>Verano<Semestre>
...doesn't look well-formed.

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

I'm trying to validate the following XML against a XSD schema using Ruby.
It simply won't work, stops with an error message telling me
Error: Element 'request': No matching global declaration available for the validation root.
Maybe it's the namespace? Any ideas?
XML
<?xml version="1.0" encoding="UTF-8"?>
<request type="test" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<channel name="channel">
<username>user</username>
<password>pass</password>
</channel>
<hotel id="1">
<date from="2009-07-07" to="2009-07-17"/>
<room id="1">
<allocation>10</allocation>
</room>
</hotel>
</request>
XSD
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- channel -->
<xsd:element name="channel">
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:sequence>
<xsd:element username="name" use="required" type="xsd:string"/>
<xsd:element password="country" use="required" type="xsd:string"/>
</xsd:sequence>
</xsd:element>
<!-- hotel -->
<xsd:element name="hotel">
<xsd:attribute name="id" use="required" type="xsd:string" />
<xsd:sequence>
<xsd:element name="hotel">
<xsd:attribute name="from" use="required" type="xsd:string" />
<xsd:attribute name="to" use="required" type="xsd:string" />
</xsd:element>
<xsd:element ref="room" minOccurs="1"/>
</xsd:sequence>
</xsd:element>
<!-- room -->
<xsd:element name="room">
<xsd:sequence>
<xsd:element name="allocation" type="xsd:string"></xsd:element>
<xsd:element ref="hotel" minOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:element>
<!-- building all together -->
<xsd:element name="request">
<xsd:attribute name="type" use="required" type="xsd:string" />
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="channel" maxOccurs="1"/>
<xsd:element ref="hotel" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Ruby code
require "xml"
document = LibXML::XML::Document.file("/tmp/test.xml")
schema = LibXML::XML::Document.file("/tmp/request.xsd")
result = document.validate_schema(schema) do |message,flag|
log.debug(message)
puts message
end
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.

Resources